The thing is: it requires a bit of a re-think about how your code does what it does. The problem is linked to the while-loop in the main function caused by, as far as I can see, the second while-loop in the function 'stopTimer'. Go see the url in my sig for a bit of a write-up that I did on how to do this. I much prefer to use classes and state machines explicitly. You can re-use the 'i' variable for all your loops: they aren't running simultaneously. I will during the sample, so long as the button is pressed turn on the led. Since you have delays inside loops, those loop variables have to become static in order to persist between invocations of loop. But i seem to have a problem on the very very. But when I removed both rules (digitalWrite and delay(1000)) the sampling time is correct. Hey, i am trying to make a device that you activate by pressing a button, then it creates a random delay, and you have to wait for this random amount of time, and when it has passed, either a led or a buzzer will go off (also randomly chosen), then you have to click again, and then it will tell you your reaction time based on two millis() timers. One way to do this - horrifying as it may be - is to use a load of gotos And also the outputValue (which is linked at the delaytime of sampling) is not going to 100. Easiest way to do this is to make 'em global. Since you have delays inside loops, those loop variables have to become static in order to persist between invocations of loop. In general - to turn blocking code with delays into non-blocking code, each point where a delay() appears becomes a state in a state machine. delay(10) Serial.println() Serial.print(Connecting to ) Serial.println(ssid). Here are my for loops if (warning_state = HIGH)ÄigitalWrite(ledPins, HIGH) //Turns on LED #i each time this runsÄigitalWrite(ledPins, LOW) //Turns on LED #i each time this runsÄigitalWrite(ledPins, LOW) // turns all lights off Dont mind the code encapsulated here - include .i have most of the code fiqured out, but what i cant get is to get the for loop to be non blocking, and thats because of the delay() used, how can i get the for loop to be non blocking? Hello everyone, so im currently working on a project where i have a bunch of for loops and i need to switch between them when a button is pushed. Heres a code to make an LED blink (here we choose the built-in LED, no need to add any external LED) every 0.5 seconds this is one of the most common.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |