c++ - Arduino timed void draw() loops -
i have arduino uno set sense light level , draw text file via processing when gets dark. i'd modify processing code interrupt draw loop 5 seconds , restart draw loop. continuously write , overwrite .txt file that's not important right now.
the purpose of excercise understand how insert break endless draw loop. i'm still newbie programming , trying wrap head around how commands interact eath other. can me understand how make work? eample code great i'd happy conceptual description of how it's supposed work...learn doing , all.
i've tried putting void draw() loop within void loop() erred out. on right path?
<setup...myserial , createwriter path/file.txt>{ } void draw() { //this needs terminate & restart if (myserial.available() > 0 ) { string value = myserial.readstring(); if ( value != null ) { output.println( value ); } } } void keypressed , end
i believe you're looking called "state machine".
make variable can use store time value, compare current time see if 5s have passed.
uint32_t last_trigger = 0; // millis() returns unsigned, 32-bit integer void setup() { serial.begin(9600); } void loop() { if (millis() - last_trigger > 5000) { // 5000 milliseconds last_trigger = millis(); // update last_trigger serial.print("last triggered @ "); // report findings serial.print(last_trigger); serial.println(" milliseconds"); } }
Comments
Post a Comment