|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- // Arduino -> Adafruit ESP32 Feather auswählen
-
- #include <WiFi.h>
- #include <WiFiUDP.h>
- #include <stdio.h>
- #include <ctype.h>
-
- /* Firmware v1.1 04.04.2019
- * Christian Schuster
- * cchschuster@gmail.com
- */
-
- #define SSID "featherNetwork" // network SSID
- #define PASSWORD "featherNetwork" // network password
-
- #define PIN_LED 13
- #define PIN_Z 14
- #define PIN_V 32
- #define PIN_R 15
- #define PIN_L 33
- #define PIN_27 27
- #define PIN_12 12
- #define PIN_13 13
- #define PIN_A5 4
- #define PIN_A1 25
- #define PIN_A0 26
-
- #define SCRIPTMODE 1 // 0 = local filtering, 1 = laptop script filtering
-
- char packetBuffer[255]; // buffer to hold incoming packet
- unsigned int localPort = 8888;
-
- char sig_nr;
- int i_sig_nr;
-
- WiFiUDP udp;
-
- void setup()
- {
- setInitGPIO();
-
- // Initialize serial
- Serial.begin(115200);
- Serial.println();
- Serial.print("Setting up AP at SSID: ");
- Serial.print(SSID);
-
- bool result = WiFi.softAP(SSID, PASSWORD);
-
- //result = false; // for error testing
- if(result)
- {
- Serial.println();
- Serial.println("...AP successfully built.");
- Serial.print("...Feather IP: ");
- Serial.println(WiFi.softAPIP());
- Serial.print("...Feather MAC: ");
- Serial.println(WiFi.softAPmacAddress());
- Serial.print("...Local port: ");
- Serial.println(localPort);
- successWiFi();
- Serial.println("Listening to port...");
- } else {
- Serial.println("...Failed while setting up access point");
- errorWiFi();
- }
-
- udp.begin(localPort);
- }
-
- void loop()
- {
- int packetSize = udp.parsePacket();
- if(packetSize)
- {
- int len = udp.read(packetBuffer, 255);
- if(len)
- {
- packetBuffer[len] = 0;
- }
-
- if(SCRIPTMODE) // == 1
- {
- // laptop script filtering
- sig_nr = packetBuffer[0];
- Serial.println(sig_nr);
- vibrate(sig_nr);
- } else {
- // local filtering
- if(strstr(packetBuffer,"usCode "))
- {
- sig_nr = packetBuffer[13];
- Serial.println(sig_nr);
- vibrate(sig_nr);
- }
- }
- }
- }
-
- void setInitGPIO()
- {
- // Set all as OUTPUT
- pinMode(PIN_LED, OUTPUT);
- pinMode(PIN_Z, OUTPUT);
- pinMode(PIN_V, OUTPUT);
- pinMode(PIN_R, OUTPUT);
- pinMode(PIN_L, OUTPUT);
-
- // Bisher ungenutzte Pins
- pinMode(PIN_27, OUTPUT);
- pinMode(PIN_12, OUTPUT);
- pinMode(PIN_13, OUTPUT);
- pinMode(PIN_A5, OUTPUT);
- pinMode(PIN_A1, OUTPUT);
- pinMode(PIN_A0, OUTPUT);
-
- allLow();
- }
-
- void allLow()
- {
- // Set all LOW
- digitalWrite(PIN_LED, LOW);
- digitalWrite(PIN_Z, LOW);
- digitalWrite(PIN_V, LOW);
- digitalWrite(PIN_R, LOW);
- digitalWrite(PIN_L, LOW);
-
- // Bisher ungenutzte Pins
- digitalWrite(PIN_27, LOW);
- digitalWrite(PIN_12, LOW);
- digitalWrite(PIN_13, LOW);
- digitalWrite(PIN_A5, LOW);
- digitalWrite(PIN_A1, LOW);
- digitalWrite(PIN_A0, LOW);
- }
-
- void errorWiFi()
- {
- delay(2000);
- while(true)
- {
- digitalWrite(PIN_LED, HIGH);
- delay(100);
- digitalWrite(PIN_LED, LOW);
- delay(100);
- digitalWrite(PIN_LED, HIGH);
- delay(100);
- digitalWrite(PIN_LED, LOW);
- delay(1000);
- }
- }
-
- void successWiFi()
- {
- delay(2000);
- for(int i = 0; i < 5; i++)
- {
- digitalWrite(PIN_LED, HIGH);
- delay(1000);
- digitalWrite(PIN_LED, LOW);
- delay(200);
- }
- }
-
- void vibrate(const char signr)
- {
- switch(signr)
- {
- case '4': digitalWrite(PIN_Z, HIGH); break;
- case '3': digitalWrite(PIN_V, HIGH); break;
- case '2': digitalWrite(PIN_R, HIGH); break;
- case '1': digitalWrite(PIN_L, HIGH); break;
- case '0': allLow(); break;
- }
- }
|