Go Down

Topic: New to the Arduino and C++ environment (LED program) (Read 11 times) previous topic - next topic


Hi, as you can see from the title I have verry little knowledge of arduino. I am tring to write a program for an LED with 3 different modes that switch with the push of  a button.




Now in general I know how to write each of these individually but have no idea how i would combine them so that it would work. If enyone would be kind enough to show me how the code should be done, so I can have it as a referance for future projects i would really apreciate it.


One approach would be to put the code for each mode in a separate function, read the input in loop() and call the appropriate function based perhaps on how many times the button has been pressed.  You will also need a way to get out of each mode so could put reading the input into a function and call that to check whether to move to another mode.

To keep the code responsive you should not use delay() in any of the modes, which I suspect will be a problem.

Things to look at :

The StateChangeDetection example in the IDE, Using millis() for timing.  A beginners guide,   Several things at the same time and look at the BlinkWithoutDelay example in the IDE.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up