Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
547e9cea72 | ||
![]() |
9338535563 |
84
arduino/ultrasonic-sensor/ultrasonic/ultrasonic.ino
Normal file
84
arduino/ultrasonic-sensor/ultrasonic/ultrasonic.ino
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include "Arduino_LED_Matrix.h"
|
||||||
|
|
||||||
|
# define PIN_TRIGGER 9 // Pin 9: PIN_TRIGGER
|
||||||
|
# define PIN_ECHO 8 // Pin 8 Empfang
|
||||||
|
|
||||||
|
// LED-Matrix leer initialisieren
|
||||||
|
byte led_frame[8][12] = {0};
|
||||||
|
ArduinoLEDMatrix matrix;
|
||||||
|
|
||||||
|
int maxDistance = 20;
|
||||||
|
|
||||||
|
// Funktion, um die LED-Höhe basierend auf der gemessenen Entfernung zu berechnen
|
||||||
|
int calc_LED_Height(int distance) {
|
||||||
|
// Begrenze die Entfernung auf die maximale Entfernung
|
||||||
|
if (distance > maxDistance) {
|
||||||
|
distance = maxDistance;
|
||||||
|
}
|
||||||
|
// Berechne die Höhe der LEDs
|
||||||
|
int ledHeight = (distance * 8) / maxDistance;
|
||||||
|
return ledHeight;
|
||||||
|
}
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
pinMode(PIN_TRIGGER, OUTPUT);
|
||||||
|
pinMode(PIN_ECHO, INPUT);
|
||||||
|
Serial.begin(9600);
|
||||||
|
matrix.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0; // Spaltenzähler in der LED-Matrix
|
||||||
|
|
||||||
|
// scroll the frame one column to the left
|
||||||
|
void scroll_matrix() {
|
||||||
|
for(int col=1; col < 12;col++) {
|
||||||
|
for(int row = 0;row <8;row++) {
|
||||||
|
led_frame[row][col-1] = led_frame[row][col];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// draw the LED frame
|
||||||
|
void draw_matrix(int leds, int count) {
|
||||||
|
if(count == 12) {
|
||||||
|
scroll_matrix();
|
||||||
|
}
|
||||||
|
for(int l =7;l >leds; l--) {
|
||||||
|
led_frame[l][count] = 1;
|
||||||
|
}
|
||||||
|
matrix.renderBitmap(led_frame, 8, 12);
|
||||||
|
|
||||||
|
}
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
long distance = 0;
|
||||||
|
|
||||||
|
// Signalstörungen vermeiden, daher einmal kurz Trigger auf LOW
|
||||||
|
digitalWrite(PIN_TRIGGER, LOW);
|
||||||
|
delay(5);
|
||||||
|
|
||||||
|
// Signal PIN_TRIGGER
|
||||||
|
digitalWrite(PIN_TRIGGER, HIGH);
|
||||||
|
delayMicroseconds(10);
|
||||||
|
digitalWrite(PIN_TRIGGER, LOW);
|
||||||
|
|
||||||
|
// pulseIn -> Signallaufzeit messen
|
||||||
|
long Zeit = pulseIn(PIN_ECHO, HIGH);
|
||||||
|
|
||||||
|
// distance in cm berechnen
|
||||||
|
distance = (Zeit / 2) * 0.03432;
|
||||||
|
|
||||||
|
// distance anzeigen
|
||||||
|
Serial.print("distance in cm: ");
|
||||||
|
Serial.println(distance);
|
||||||
|
|
||||||
|
// Anzahl der LEDs in der Spalte berechnen
|
||||||
|
int leds = calc_LED_Height(distance);
|
||||||
|
|
||||||
|
// Matrix neuzeichnen
|
||||||
|
draw_matrix(leds,count);
|
||||||
|
delay(1000);
|
||||||
|
if( count < 12) { // maximal 12 Spalten, danach wird gescrollt.
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
3
arduino/uno-r4-wifi/webserver-async/arduino_secrets.h
Normal file
3
arduino/uno-r4-wifi/webserver-async/arduino_secrets.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
#define SECRET_SSID "Echo Base Attack"
|
||||||
|
#define SECRET_PASS "99LaiWzH."
|
114
arduino/uno-r4-wifi/webserver-async/webserver-async.ino
Normal file
114
arduino/uno-r4-wifi/webserver-async/webserver-async.ino
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
#include "WiFi.h"
|
||||||
|
#include <WiFiS3.h>
|
||||||
|
#include "ESPASyncWebServer.h"
|
||||||
|
#include "Arduino_LED_Matrix.h"
|
||||||
|
#include "arduino_secrets.h"
|
||||||
|
|
||||||
|
char ssid[] = SECRET_SSID;
|
||||||
|
char pw[] = SECRET_PASS;
|
||||||
|
byte frame_horizontal[8][12] ={
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
};
|
||||||
|
byte frame_vertical[8][12] ={
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
ASyncWebserver server(80);
|
||||||
|
|
||||||
|
void debug(char * msg, char *var) {
|
||||||
|
Serial.print(msg);
|
||||||
|
Serial.println(var);
|
||||||
|
}
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600); // initialize serial communication
|
||||||
|
|
||||||
|
// check for the WiFi module:
|
||||||
|
if (WiFi.status() == WL_NO_MODULE) {
|
||||||
|
Serial.println("Communication with WiFi module failed!");
|
||||||
|
// don't continue
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fv = WiFi.firmwareVersion();
|
||||||
|
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||||
|
Serial.println("Please upgrade the firmware");
|
||||||
|
}
|
||||||
|
|
||||||
|
long count = 0;
|
||||||
|
|
||||||
|
// attempt to connect to WiFi network:
|
||||||
|
|
||||||
|
int status = WL_IDLE_STATUS;
|
||||||
|
|
||||||
|
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(1000);
|
||||||
|
}
|
||||||
|
Serial.println("erzeuge Server");
|
||||||
|
server.begin(); // start the web server on port 80
|
||||||
|
printWifiStatus();
|
||||||
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
|
|
||||||
|
int paramsNr = request->params();
|
||||||
|
Serial.println(paramsNr);
|
||||||
|
|
||||||
|
for(int i=0;i<paramsNr;i++){
|
||||||
|
|
||||||
|
AsyncWebParameter *p = request->getParam(i);
|
||||||
|
Serial.print("Param name: ");
|
||||||
|
Serial.println(p->name());
|
||||||
|
Serial.print("Param value: ");
|
||||||
|
Serial.println(p->value());
|
||||||
|
Serial.println("------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
request->send(200, "text/plain", "message received"); // you're connected now, so print out the status
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void printWifiStatus() {
|
||||||
|
//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);
|
||||||
|
}
|
163
arduino/uno-r4-wifi/webserver-async/wifis3.ino
Normal file
163
arduino/uno-r4-wifi/webserver-async/wifis3.ino
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#include "Arduino_LED_Matrix.h"
|
||||||
|
#include "WiFiS3.h"
|
||||||
|
#include "arduino_secrets.h"
|
||||||
|
|
||||||
|
char ssid[] = SECRET_SSID;
|
||||||
|
char pw[] = SECRET_PASS;
|
||||||
|
byte frame_horizontal[8][12] ={
|
||||||
|
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },
|
||||||
|
};
|
||||||
|
byte frame_vertical[8][12] ={
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
{ 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, },
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
WiFiServer server(80);
|
||||||
|
|
||||||
|
void debug(char * msg, char *var) {
|
||||||
|
Serial.print(msg);
|
||||||
|
Serial.println(var);
|
||||||
|
}
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600); // initialize serial communication
|
||||||
|
|
||||||
|
// check for the WiFi module:
|
||||||
|
if (WiFi.status() == WL_NO_MODULE) {
|
||||||
|
Serial.println("Communication with WiFi module failed!");
|
||||||
|
// don't continue
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
String fv = WiFi.firmwareVersion();
|
||||||
|
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||||
|
Serial.println("Please upgrade the firmware");
|
||||||
|
}
|
||||||
|
|
||||||
|
long count = 0;
|
||||||
|
|
||||||
|
// attempt to connect to WiFi network:
|
||||||
|
|
||||||
|
int status = WL_IDLE_STATUS;
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
char fullurl[2048];
|
||||||
|
int urlcount=0;
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
//Serial.println("waiting for connection...");
|
||||||
|
|
||||||
|
WiFiClient client = server.available(); // listen for incoming clients
|
||||||
|
|
||||||
|
// Serial.println(client);
|
||||||
|
if (client) {
|
||||||
|
client.o // 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
|
||||||
|
boolean currentLineIsBlank = true;
|
||||||
|
boolean firstLine = true; /* only the first line in the array */
|
||||||
|
while (client.connected()) { // loop while the client's connected
|
||||||
|
if (client.available()) { // if there's bytes to read from the client,
|
||||||
|
String HTTP_header = client.readStringUntil('\n'); // read the header line of HTTP request
|
||||||
|
if(HTTP_header.equals("\r")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
char c = client.read(); // read a byte, then
|
||||||
|
if(firstLine && urlcount < 2048) {
|
||||||
|
fullurl[urlcount] = c;
|
||||||
|
urlcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == '\n') {
|
||||||
|
// you're starting a new line
|
||||||
|
currentLineIsBlank = true;
|
||||||
|
firstLine = false;
|
||||||
|
|
||||||
|
} else if (c != '\r') {
|
||||||
|
// you've gotten a character on the current line
|
||||||
|
currentLineIsBlank = false;
|
||||||
|
}
|
||||||
|
if (c == '\n' && currentLineIsBlank) {
|
||||||
|
// send a standard http response header
|
||||||
|
client.println("OK");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug("fullurl=",fullurl);
|
||||||
|
// if you've gotten to the end of the line (received a newline
|
||||||
|
// character) and the line is blank, the http request has ended,
|
||||||
|
// so you can send a reply
|
||||||
|
sendResponse(client);
|
||||||
|
|
||||||
|
}
|
||||||
|
// close the connection:
|
||||||
|
client.stop();
|
||||||
|
// Serial.println("client disconnected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void sendResponse(WiFiClient client) {
|
||||||
|
// send the HTTP response
|
||||||
|
// send the HTTP response header
|
||||||
|
// Serial.println("sending response");
|
||||||
|
client.println("HTTP/1.1 200 OK");
|
||||||
|
client.println("Content-Type: text/html");
|
||||||
|
client.println("Connection: close"); // the connection will be closed after completion of the response
|
||||||
|
client.println(); // the separator between HTTP header and body
|
||||||
|
// send the HTTP response body
|
||||||
|
client.println("<!DOCTYPE HTML>");
|
||||||
|
client.println("<html>");
|
||||||
|
client.println("<head>");
|
||||||
|
client.println("<link rel=\"icon\" href=\"data:,\">");
|
||||||
|
client.println("</head>");
|
||||||
|
|
||||||
|
client.println("<p>");
|
||||||
|
}
|
||||||
|
void printWifiStatus() {
|
||||||
|
//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);
|
||||||
|
}
|
Reference in New Issue
Block a user