This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
maakplek_statusmelder [2019/03/13 13:54] – created wrusman | maakplek_statusmelder [2019/03/13 15:36] – wrusman | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Maakplek statusmelder ====== | ||
+ | |||
+ | ==== Schakelaar box met ESP8266 ==== | ||
+ | Gemaakt door Jasper | ||
+ | |||
+ | De ESP8266 maakt verbinding met wifi en stuurt bij het omhalen van de schakelaar een bericht naar de twitter API van pushingbox. Zijn 3.3v voeding krijgt hij via een spanningsregelaar die is aangesloten op de vcc uitgang van de pro micro.\\ De esp8266 heeft twee boot modes : met de schakelaar op " | ||
+ | |||
+ | code voor de esp8266: | ||
+ | < | ||
+ | #include < | ||
+ | |||
+ | #define AP_SSID | ||
+ | #define AP_PASSWORD " | ||
+ | |||
+ | #define API_SERVER | ||
+ | #define API_KEY | ||
+ | |||
+ | #define ledPin 0 | ||
+ | #define switchPin 2 | ||
+ | |||
+ | int switchState = false; | ||
+ | int lastSwitchState = false; | ||
+ | int lastConnected = false; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
+ | pinMode(switchPin, | ||
+ | pinMode(ledPin, | ||
+ | wifiConnect(); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | switchState = digitalRead(switchPin); | ||
+ | if (switchState != lastSwitchState) { | ||
+ | if (switchState == HIGH) { | ||
+ | WiFiClient client; | ||
+ | if (!client.connect(API_SERVER, | ||
+ | { | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
+ | client.print(" | ||
+ | client.print(API_KEY); | ||
+ | client.print("& | ||
+ | client.println(" | ||
+ | client.print(" | ||
+ | client.println(API_SERVER); | ||
+ | client.println(); | ||
+ | |||
+ | digitalWrite(ledPin, | ||
+ | |||
+ | Serial.println(" | ||
+ | |||
+ | delay(10); | ||
+ | } | ||
+ | else { | ||
+ | WiFiClient client; | ||
+ | if (!client.connect(API_SERVER, | ||
+ | { | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
+ | client.print(" | ||
+ | client.print(API_KEY); | ||
+ | client.print("& | ||
+ | client.println(" | ||
+ | client.print(" | ||
+ | client.println(API_SERVER); | ||
+ | client.println(); | ||
+ | |||
+ | digitalWrite(ledPin, | ||
+ | |||
+ | Serial.println(" | ||
+ | |||
+ | delay(10); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | lastSwitchState = switchState; | ||
+ | |||
+ | } | ||
+ | void wifiConnect() | ||
+ | { | ||
+ | Serial.print( " | ||
+ | Serial.print( AP_SSID ); | ||
+ | WiFi.begin( AP_SSID, AP_PASSWORD ); | ||
+ | while ( WiFi.status() != WL_CONNECTED ) | ||
+ | { | ||
+ | delay( 1000 ); | ||
+ | Serial.print( " | ||
+ | } | ||
+ | |||
+ | Serial.println( "" | ||
+ | Serial.println( "WiFi connected" | ||
+ | |||
+ | Serial.println( WiFi.localIP( ) ); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Telefoonbox met Arduino pro micro ==== | ||
+ | uitbreiding gemaakt door Wouter R | ||
+ | |||
+ | De arduino pro micro is via USB-OTG verbonden met een lader en de telefoon zodat de telefoon oplaad en via muis/ | ||
+ | Via deze methode wordt via keyboard commando' | ||
+ | Onderop het kastje zit een schakelaar achter de draad waarmee de arduino zorgt dat hij niets via de HID interface typt. \\Dit is vooral handig voor tijdens het opstarten van de hele combinatie of tijdens het schrijven van de code in de arduino (anders begint hij vrolijk in je arduino editor te typen). | ||
+ | |||
+ | {{:: | ||
+ | |||
+ | |||
+ | Code voor de Arduino Pro Mini: | ||
< | < | ||
#include " | #include " | ||
Line 7: | Line 118: | ||
int buttonState = LOW; // the current reading from the input pin | int buttonState = LOW; // the current reading from the input pin | ||
int lastButtonState = LOW; // the previous reading from the input pin | int lastButtonState = LOW; // the previous reading from the input pin | ||
- | int maakplekState = LOW; | + | int maakplekState = LOW; |
- | + | ||
- | unsigned long lastDebounceTime = 0; | + | |
- | unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers | + | |
void setup() { | void setup() { |