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 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); |
||||
|
|
||||
|
} |
@ -1,91 +1,85 @@ |
|||||
#include "Arduino_LED_Matrix.h" |
#include <WiFiS3.h> |
||||
#include "WiFiS3.h" |
#include <Arduino.h> |
||||
#include "arduino_secrets.h" |
#include "arduino_secrets.h" |
||||
|
|
||||
char ssid[] = SECRET_SSID; |
// Netzwerk ws_ssid und Passwort
|
||||
char pw[] = SECRET_PASS; |
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() { |
void setup() { |
||||
Serial.begin(9600); // initialize serial communication
|
// Serielle Kommunikation starten
|
||||
|
Serial.begin(9600); |
||||
|
while (!Serial); |
||||
|
|
||||
|
// Mit dem WLAN verbinden
|
||||
|
Serial.print("Verbinde mit "); |
||||
|
Serial.println(ws_ssid); |
||||
|
WiFi.begin(ws_ssid, ws_pass); |
||||
|
|
||||
// check for the WiFi module:
|
// Warten, bis die Verbindung hergestellt ist
|
||||
if (WiFi.status() == WL_NO_MODULE) { |
while (WiFi.status() != WL_CONNECTED) { |
||||
Serial.println("Communication with WiFi module failed!"); |
delay(500); |
||||
// don't continue
|
Serial.print("."); |
||||
while (true); |
|
||||
} |
} |
||||
|
|
||||
String fv = WiFi.firmwareVersion(); |
// Verbunden, IP-Adresse ausgeben
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) { |
Serial.println(""); |
||||
Serial.println("Please upgrade the firmware"); |
Serial.println("WiFi verbunden."); |
||||
|
Serial.print("IP Adresse: "); |
||||
|
Serial.println(WiFi.localIP()); |
||||
|
|
||||
|
// Webserver starten
|
||||
|
webserver.begin(); |
||||
} |
} |
||||
|
|
||||
long count = 0; |
void loop() { |
||||
|
// Auf einen neuen Client warten
|
||||
|
WiFiClient client = webserver.available(); |
||||
|
|
||||
|
if (client) { |
||||
|
Serial.println("Neuer Client verbunden"); |
||||
|
String currentLine = ""; |
||||
|
String header = ""; |
||||
|
|
||||
// attempt to connect to WiFi network:
|
// Aktuelle Zeit erfassen
|
||||
|
unsigned long currentTime = millis(); |
||||
|
unsigned long previousTime = currentTime; |
||||
|
|
||||
int status = WL_IDLE_STATUS; |
// Zeitüberschreitung für die Verbindung (2000 ms)
|
||||
|
const unsigned long timeoutTime = 2000; |
||||
|
|
||||
while (status != WL_CONNECTED) { |
while (client.connected() && (currentTime - previousTime <= timeoutTime)) { |
||||
debug("trying to connect to ",ssid); |
currentTime = millis(); |
||||
status = WiFi.begin(ssid, pw); |
if (client.available()) { |
||||
// Serial.print("status =");
|
char c = client.read(); |
||||
// Serial.println(WiFi.status());
|
Serial.write(c); |
||||
char scount[10]; |
header += c; |
||||
sprintf(scount, "%d", count); |
if (c == '\n') { |
||||
debug("Retry count: ", scount); |
if (currentLine.length() == 0) { |
||||
count++; |
client.println("HTTP/1.1 200 OK"); |
||||
// wait 10 seconds for connection:
|
client.println("Content-type:text/html"); |
||||
delay(5000); |
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 = ""; |
||||
} |
} |
||||
Serial.println("erzeuge Server"); |
} else if (c != '\r') { |
||||
server.begin(); // start the web server on port 80
|
currentLine += c; |
||||
printWifiStatus(); // you're connected now, so print out the status
|
|
||||
} |
} |
||||
|
|
||||
void loop() { |
|
||||
WiFiClient client = server.available(); // listen for incoming clients
|
|
||||
|
|
||||
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
|
|
||||
} |
} |
||||
} |
} |
||||
|
|
||||
} |
// Header und Client-Verbindung schließen
|
||||
// close the connection:
|
header = ""; |
||||
client.stop(); |
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