Loading...
Pages: [1]   Go Down
Author Topic: momentary button and programs  (Read 162 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am very new to the Arduino world and doing my best to teach myself, so bear with the newbie questions..
I'd like to have a momentary button change program loops each time I press it. I can make an LED going on and off with a button/debounce code but where do I go from there? For now I want to press button- light goes on, press button - light blinks..etc..
Thanks ahead for any help and patience..
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 242
Posts: 16471
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I just answered this in another thread smiley-cool
Code:
void loop(){
if (digitalRead (button)==0){ // assumes button declared as INPUT with internal pullup enabled
programState = programState +1;
if (programState ==5){  // reset after 5, or whatever amount you select
programState = 1;
delay (25); // may not need if the programs run long enough for the button to debounce
}
switch(programState):
case 1:
// do program 1
break;
case 2:
// do program 2
break;
case 3:
// do program 3
break;

case 4:
// do program 4
break;

case 5:
// do program 5
break;
}
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Offline Offline
Newbie
*
Karma: 0
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey CrossRoads, Thanks! I think I did see your post as I read down the line today...
Many thanks..I am sure I'll have more questions soon...
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 242
Posts: 16471
Available for Design & Build services
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I may be aroud to answer smiley-wink
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17

Pages: [1]   Go Up
Print
 
Jump to: