3 changed files with 183 additions and 71 deletions
@ -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; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,57 @@ |
|||
|
|||
#include "Arduino_LED_Matrix.h" |
|||
|
|||
ArduinoLEDMatrix matr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 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); |
|||
|
|||
} |
@ -1,91 +1,85 @@ |
|||
#include "Arduino_LED_Matrix.h" |
|||
#include "WiFiS3.h" |
|||
#include <WiFiS3.h> |
|||
#include <Arduino.h> |
|||
#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 = ""; |
|||
|
|||
// Aktuelle Zeit erfassen
|
|||
unsigned long currentTime = millis(); |
|||
unsigned long previousTime = currentTime; |
|||
|
|||
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
|
|||
// 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("<!DOCTYPE HTML>"); |
|||
client.println("<html>"); |
|||
client.println("<head><title>Arduino Webserver</title></head>"); |
|||
client.println("<body><h1>Hallo vom Arduino Uno R4 WiFi!</h1></body>"); |
|||
client.println("</html>"); |
|||
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); |
|||
} |
Loading…
Reference in new issue