Her er en motorstyring for Blynk. Motoren kan enten startes og stoppes fra lokale brytere eller fra mobiltelefon via Blynk.
Man må også lage en app på mobiltelefonen pluss at man må konfigurere riktig port i filen C:\Users\Win\Documents\Arduino\libraries\Blynk\scripts\blynk-ser.bat
Programkode:
#include <BlynkSimpleStream.h> char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; void setup() { pinMode(2, INPUT); pinMode(3, INPUT); pinMode(10, OUTPUT); Serial.begin(9600); Blynk.begin(Serial, auth); } int rstart; BLYNK_WRITE(V1) { rstart = param.asInt(); } int rstop; BLYNK_WRITE(V2) { rstop = param.asInt(); } void loop() { Blynk.run(); if (digitalRead(2) || rstart){digitalWrite(10,1);} if (digitalRead(3) || rstop){digitalWrite(10,0); } if (digitalRead(10)){Blynk.virtualWrite(V3, 255);} if (!digitalRead(10)){Blynk.virtualWrite(V3, 0);} delay(20); }
Forbedret programkode som gir redusert datatrafikk:
#include <BlynkSimpleStream.h> char auth[] = "zbjoXyfO2Za3FtFLSrD_x52HXBzo__vd"; BlynkTimer timer; // Read start signal from phone int rstart; BLYNK_WRITE(V1) { rstart = param.asInt(); } // Read stop signal from phone int rstop; BLYNK_WRITE(V2) { rstop = param.asInt(); } void myTimerEvent() { if (digitalRead(2) || rstart){digitalWrite(10,1);} if (digitalRead(3) || rstop){digitalWrite(10,0);} // Write confirmation feedback on V4: if (digitalRead(10)){Blynk.virtualWrite(V4, 255);} else {Blynk.virtualWrite(V4, 0);} } void setup() { pinMode(2, INPUT); pinMode(3, INPUT); pinMode(10, OUTPUT); Serial.begin(9600); Blynk.begin(Serial, auth); timer.setInterval(1000L, myTimerEvent); } void loop() { Blynk.run(); timer.run(); }