You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tactile_eeg_v1.1-hardwaretest.ino 4.1KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // Arduino -> Adafruit ESP32 Feather auswählen
  2. #include <WiFi.h>
  3. #include <WiFiUDP.h>
  4. #include <stdio.h>
  5. #include <ctype.h>
  6. /* Martin Wimmer Hardwaretest 17.04.2019
  7. * Firmware v1.1 04.04.2019
  8. * Christian Schuster
  9. * cchschuster@gmail.com
  10. */
  11. #define SSID "featherNetwork" // network SSID
  12. #define PASSWORD "featherNetwork" // network password
  13. #define PIN_LED 13
  14. #define PIN_Z 14
  15. #define PIN_V 32
  16. #define PIN_R 15
  17. #define PIN_L 33
  18. #define PIN_27 27
  19. #define PIN_12 12
  20. #define PIN_13 13
  21. #define PIN_A5 4
  22. #define PIN_A1 25
  23. #define PIN_A0 26
  24. #define SCRIPTMODE 1 // 0 = local filtering, 1 = laptop script filtering
  25. char packetBuffer[255]; // buffer to hold incoming packet
  26. unsigned int localPort = 8888;
  27. char sig_nr;
  28. int i_sig_nr;
  29. WiFiUDP udp;
  30. void setup()
  31. {
  32. setInitGPIO();
  33. // Initialize serial
  34. Serial.begin(115200);
  35. Serial.println();
  36. Serial.print("Setting up AP at SSID: ");
  37. Serial.print(SSID);
  38. bool result = WiFi.softAP(SSID, PASSWORD);
  39. //result = false; // for error testing
  40. if(result)
  41. {
  42. Serial.println();
  43. Serial.println("...AP successfully built.");
  44. Serial.print("...Feather IP: ");
  45. Serial.println(WiFi.softAPIP());
  46. Serial.print("...Feather MAC: ");
  47. Serial.println(WiFi.softAPmacAddress());
  48. Serial.print("...Local port: ");
  49. Serial.println(localPort);
  50. successWiFi();
  51. Serial.println("Listening to port...");
  52. } else {
  53. Serial.println("...Failed while setting up access point");
  54. errorWiFi();
  55. }
  56. udp.begin(localPort);
  57. }
  58. void loop()
  59. {
  60. /*
  61. int packetSize = udp.parsePacket();
  62. if(packetSize)
  63. {
  64. int len = udp.read(packetBuffer, 255);
  65. if(len)
  66. {
  67. packetBuffer[len] = 0;
  68. }
  69. if(SCRIPTMODE) // == 1
  70. {
  71. // laptop script filtering
  72. sig_nr = packetBuffer[0];
  73. Serial.println(sig_nr);
  74. vibrate(sig_nr);
  75. } else {
  76. // local filtering
  77. if(strstr(packetBuffer,"usCode "))
  78. {
  79. sig_nr = packetBuffer[13];
  80. Serial.println(sig_nr);
  81. vibrate(sig_nr);
  82. }
  83. }
  84. }
  85. */
  86. // Test alle Kanäle
  87. allHigh();
  88. delay(1000);
  89. allLow();
  90. delay(1000);
  91. /*
  92. // Test Kanal L,R,V,Z
  93. for(char i='1' ; i<='4' ; i++)
  94. {
  95. vibrate(i);
  96. delay(1000);
  97. vibrate('0');
  98. delay(1000);
  99. }
  100. */
  101. }
  102. void setInitGPIO()
  103. {
  104. // Set all as OUTPUT
  105. pinMode(PIN_LED, OUTPUT);
  106. pinMode(PIN_Z, OUTPUT);
  107. pinMode(PIN_V, OUTPUT);
  108. pinMode(PIN_R, OUTPUT);
  109. pinMode(PIN_L, OUTPUT);
  110. // Bisher ungenutzte Pins
  111. pinMode(PIN_27, OUTPUT);
  112. pinMode(PIN_12, OUTPUT);
  113. pinMode(PIN_13, OUTPUT);
  114. pinMode(PIN_A5, OUTPUT);
  115. pinMode(PIN_A1, OUTPUT);
  116. pinMode(PIN_A0, OUTPUT);
  117. allLow();
  118. }
  119. void allLow()
  120. {
  121. // Set all LOW
  122. digitalWrite(PIN_LED, LOW);
  123. digitalWrite(PIN_Z, LOW);
  124. digitalWrite(PIN_V, LOW);
  125. digitalWrite(PIN_R, LOW);
  126. digitalWrite(PIN_L, LOW);
  127. // Bisher ungenutzte Pins
  128. digitalWrite(PIN_27, LOW);
  129. digitalWrite(PIN_12, LOW);
  130. digitalWrite(PIN_13, LOW);
  131. digitalWrite(PIN_A5, LOW);
  132. digitalWrite(PIN_A1, LOW);
  133. digitalWrite(PIN_A0, LOW);
  134. }
  135. void errorWiFi()
  136. {
  137. delay(2000);
  138. while(true)
  139. {
  140. digitalWrite(PIN_LED, HIGH);
  141. delay(100);
  142. digitalWrite(PIN_LED, LOW);
  143. delay(100);
  144. digitalWrite(PIN_LED, HIGH);
  145. delay(100);
  146. digitalWrite(PIN_LED, LOW);
  147. delay(1000);
  148. }
  149. }
  150. void successWiFi()
  151. {
  152. delay(2000);
  153. for(int i = 0; i < 5; i++)
  154. {
  155. digitalWrite(PIN_LED, HIGH);
  156. delay(1000);
  157. digitalWrite(PIN_LED, LOW);
  158. delay(200);
  159. }
  160. }
  161. void vibrate(const char signr)
  162. {
  163. switch(signr)
  164. {
  165. case '4': digitalWrite(PIN_Z, HIGH); break;
  166. case '3': digitalWrite(PIN_V, HIGH); break;
  167. case '2': digitalWrite(PIN_R, HIGH); break;
  168. case '1': digitalWrite(PIN_L, HIGH); break;
  169. case '0': allLow(); break;
  170. }
  171. }
  172. void allHigh()
  173. {
  174. // Set all High
  175. digitalWrite(PIN_LED, HIGH);
  176. digitalWrite(PIN_Z, HIGH);
  177. digitalWrite(PIN_V, HIGH);
  178. digitalWrite(PIN_R, HIGH);
  179. digitalWrite(PIN_L, HIGH);
  180. // Bisher ungenutzte Pins
  181. digitalWrite(PIN_27, HIGH);
  182. digitalWrite(PIN_12, HIGH);
  183. digitalWrite(PIN_13, HIGH);
  184. digitalWrite(PIN_A5, HIGH);
  185. digitalWrite(PIN_A1, HIGH);
  186. digitalWrite(PIN_A0, HIGH);
  187. }