Old_val = val // Val is now old val so its stored State = 1 - state //Check if state has changed Val =digitalRead(BUTTON) //Reads the value of the button and stores PinMode(BUTTON, INPUT) //Sets Button as input Int old_val = 0 // Previous version of val Int state = 0 //0 Shows LED off 1 is LED on Int val = 0 //Val used to store input of Switch or pin 7 6 LED Chaser Pins 8 - 13Ĭonst int BUTTON = 7 //Pin 7 can be referred to as BUTTON This is what i had after attempting to add a button in, I used a slihgtly different method but i still dont see why it won't work properly. Void centerchase() // The second function PinMode(LED1, OUTPUT) //Sets all the LED's as outputs.Ĭenterchase() //Runs Function 2 - Centerchase This is what i Had Previously: //6 LED Chaser Pins 8 - 13Ĭonst int LED6 = 8 //PIns 8 -13 can be referred to as LEDs 1 - 6 I had to hold the button until the loop had restarted, this is because in the functions i am using I have delays between LED illumination. You need to try though.įair enough, Thanks for the motivation! I understand about setting the switches with the state change, but a problem i came across was not being able to press the button thereby changing the function in the middle of the function itself. If i past in the code i have so far could you help me apply your solutions into it?Īfter you try, if you have issues, by all means post and ask for help. One mans weakness is another mans strength! Its a mighty big ask, but it may also be a simple answer. If (***During function 3 Button is pressed***) If (***During function 2 Button is pressed***) If (***During function 1 Button is pressed***) In between the *** *** Is basically what i need to know how to do, but i also need it to be able to do that in the middle of a function not just at the finish of each function loop. Imagine below that i have already set up the program and the functions are written out where stated "BLAH". When you push it, it starts function 1, again will stop one and start 2, again will start 3 and stop 2, and the final time will stop 3. What i want to achieve is to have a single tactile button. Okay, so I'm really getting stuck in to some basic programming with my arduino but there's one thing I just cant seem do do efficiently.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |