diff --git a/arduino/uno-r3/ampel.ino b/arduino/uno-r3/ampel.ino new file mode 100644 index 0000000..cb39303 --- /dev/null +++ b/arduino/uno-r3/ampel.ino @@ -0,0 +1,61 @@ +int ledRot = 10; +int ledGelb = 11; +int ledGruen = 12; +boolean blinkmode = false; +int phase = 1;// Ampelphase + +void setup() { + // put your setup code here, to run once: + pinMode(ledRot, OUTPUT); + pinMode(ledGelb, OUTPUT); + pinMode(ledGruen, OUTPUT); +} + +void loop() { + + // put your main code here, to run repeatedly: + if(blinkmode) { + // Blinkmodus + digitalWrite(ledRot, HIGH); + digitalWrite(ledGelb, HIGH); + digitalWrite(ledGruen, HIGH); + delay(1500); + digitalWrite(ledRot, LOW); + digitalWrite(ledGelb, LOW); + digitalWrite(ledGruen, LOW); + delay(200); + } + else { + // Ampelmodus + switch(phase) { + case 1: // Phase rot + digitalWrite(ledRot, HIGH); + digitalWrite(ledGelb, LOW); + digitalWrite(ledGruen, LOW); + delay(1500); + phase = 2; + break; + case 2: // Phase Rot/Gelb + digitalWrite(ledRot, HIGH); + digitalWrite(ledGelb, HIGH); + digitalWrite(ledGruen, LOW); + delay(1000); + phase = 3; + break; + case 3: // Phase Grün + digitalWrite(ledRot, LOW); + digitalWrite(ledGelb, LOW); + digitalWrite(ledGruen, HIGH); + delay(2000); + phase = 4; + break; + case 4: // Phase Gelb + digitalWrite(ledRot, LOW); + digitalWrite(ledGelb, HIGH); + digitalWrite(ledGruen, LOW); + delay(1500); + phase = 1; + break; + } + } +} diff --git a/arduino/uno-r4-wifi/led_matrix/led_matrix.ino b/arduino/uno-r4-wifi/led_matrix/led_matrix.ino new file mode 100644 index 0000000..7b2983b --- /dev/null +++ b/arduino/uno-r4-wifi/led_matrix/led_matrix.ino @@ -0,0 +1,57 @@ + +#include "Arduino_LED_Matrix.h" + +ArduinoLEDMatrix matrix; + +/*byte frame[8][12] = { + { 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 }, + { 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0 }, + { 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 }, + { 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 }, + { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } +}; +*/ +/* byte frame[8][12] ={ +{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, +{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, +{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, +{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, }, +{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }, +{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, }, +{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, }, +{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, } +}; +*/ +byte frame[8][12] ={ +{ 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, }, +{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, }, +{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, }, +{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, }, +{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, }, +{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, }, +{ 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, }, +{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, + +}; + + +/*unsigned long frame[] = { + 0x3184a444, + 0x42081100, + 0xa0040000 +}; +*/ + +void setup() { + Serial.begin(115200); + matrix.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + matrix.renderBitmap(frame, 8, 12); + +} diff --git a/arduino/uno-r4-wifi/wifi/wifi.ino b/arduino/uno-r4-wifi/wifi/wifi.ino index c9310bf..050d4ec 100644 --- a/arduino/uno-r4-wifi/wifi/wifi.ino +++ b/arduino/uno-r4-wifi/wifi/wifi.ino @@ -1,91 +1,85 @@ -#include "Arduino_LED_Matrix.h" -#include "WiFiS3.h" +#include +#include #include "arduino_secrets.h" -char ssid[] = SECRET_SSID; -char pw[] = SECRET_PASS; +// Netzwerk ws_ssid und Passwort +const char* ws_ssid = SECRET_SSID; +const char* ws_pass = SECRET_PASS; -WiFiServer server(80); +// WiFiServer-Objekt erstellen, das auf Port 80 hört +WiFiServer webserver(80); - void debug(char * msg, char *var) { - Serial.print(msg); - Serial.println(var); - } void setup() { - Serial.begin(9600); // initialize serial communication + // Serielle Kommunikation starten + Serial.begin(9600); + while (!Serial); - // check for the WiFi module: - if (WiFi.status() == WL_NO_MODULE) { - Serial.println("Communication with WiFi module failed!"); - // don't continue - while (true); - } + // Mit dem WLAN verbinden + Serial.print("Verbinde mit "); + Serial.println(ws_ssid); + WiFi.begin(ws_ssid, ws_pass); - String fv = WiFi.firmwareVersion(); - if (fv < WIFI_FIRMWARE_LATEST_VERSION) { - Serial.println("Please upgrade the firmware"); + // Warten, bis die Verbindung hergestellt ist + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); } - long count = 0; - - // attempt to connect to WiFi network: - - int status = WL_IDLE_STATUS; + // Verbunden, IP-Adresse ausgeben + Serial.println(""); + Serial.println("WiFi verbunden."); + Serial.print("IP Adresse: "); + Serial.println(WiFi.localIP()); - while (status != WL_CONNECTED) { - debug("trying to connect to ",ssid); - status = WiFi.begin(ssid, pw); -// Serial.print("status ="); -// Serial.println(WiFi.status()); - char scount[10]; - sprintf(scount, "%d", count); - debug("Retry count: ", scount); - count++; - // wait 10 seconds for connection: - delay(5000); - } - Serial.println("erzeuge Server"); - server.begin(); // start the web server on port 80 - printWifiStatus(); // you're connected now, so print out the status + // Webserver starten + webserver.begin(); } void loop() { -WiFiClient client = server.available(); // listen for incoming clients + // Auf einen neuen Client warten + WiFiClient client = webserver.available(); + + if (client) { + Serial.println("Neuer Client verbunden"); + String currentLine = ""; + String header = ""; - if (client) { // if you get a client, - Serial.println("new client"); // print a message out the serial port - String currentLine = ""; // make a String to hold incoming data from the client - while (client.connected()) { // loop while the client's connected - if (client.available()) { // if there's bytes to read from the client, - char c = client.read(); // read a byte, then - Serial.write(c); // print it out to the serial monitor - if (c == '\n') { // if the byte is a newline character - digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off + // Aktuelle Zeit erfassen + unsigned long currentTime = millis(); + unsigned long previousTime = currentTime; + + // Zeitüberschreitung für die Verbindung (2000 ms) + const unsigned long timeoutTime = 2000; + + while (client.connected() && (currentTime - previousTime <= timeoutTime)) { + currentTime = millis(); + if (client.available()) { + char c = client.read(); + Serial.write(c); + header += c; + if (c == '\n') { + if (currentLine.length() == 0) { + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + client.println(""); + client.println(""); + client.println("Arduino Webserver"); + client.println("

Hallo vom Arduino Uno R4 WiFi!

"); + client.println(""); + break; + } else { + currentLine = ""; + } + } else if (c != '\r') { + currentLine += c; } } - } - // close the connection: + + // Header und Client-Verbindung schließen + header = ""; client.stop(); - Serial.println("client disconnected"); + Serial.println("Client-Verbindung geschlossen"); } } -void printWifiStatus() { - // print the SSID of the network you're attached to: - Serial.print("SSID: "); - Serial.println(WiFi.SSID()); - - // print your board's IP address: - IPAddress ip = WiFi.localIP(); - Serial.print("IP Address: "); - Serial.println(ip); - - // print the received signal strength: - long rssi = WiFi.RSSI(); - Serial.print("signal strength (RSSI):"); - Serial.print(rssi); - Serial.println(" dBm"); - // print where to go in a browser: - Serial.print("To see this page in action, open a browser to http://"); - Serial.println(ip); -} \ No newline at end of file