As i have said, this is a custom function and is not inside void setup or void loop and works for all buttons, so you don´t need to repeat. Switch allows you to choose between several discrete options. When a case statement is found whose value. When there are more than two options, you can use multiple if statements, or you can use the switch statement. I use the name of function as prefix "_up" to don´t mess the code.ģ)_Create a custom function to read pins and "watch" if the state of pins has changed (from low to high) and return what pin state has changed. In particular, a switch statement compares the value of a variable to the values specified in case statements. Normally, i put the same name of what will do, in this case "up".Will be called later by a custom functionĢ)_Create and store the states (last and current) as boolean. Let´s take the pin8 (up button) as example:ġ)_Declare pin 8. I have used the next function to use push buttons (worked for me for years) they are configured as pull down, that means the pin are always conected to gnd by 10K resistor (LOW) and when you press the button will be conected to 5v (HIGH). When the statements in a case matches the value of a variable, the code associated with that case executes. A switch statement compares a particular value of a variable with statements in other cases. With the buttons we add or subtract 1 and move the counter from 1 to 3 (total of pages). The switch case controls the flow of the program by executing the code in various cases. Once a light sequence is initiated, Id like for it to loop while also continuing to monitor for new input. Int page_counter=1 //To move beetwen pages Hello, Im working towards code that reads multiple inputs and then changes the sequence in which 5 LEDs are lit up. I also want to add the targets size (0-160) and send that also, but I’m at a loss on how to separate the 2 variables. Right now I’ve only got the targets X screen position being sent and it seems to work fine. To get multiple screens we will create a variable called "page_counter" and the default value is 1 (first page or home page). Ive got Roborealm sending a targets position serially to an Arduino which controls a Sabertooth motor controller. I will assume you are familiar with lcd 16x2 and his functions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |