Show Posts
Pages: 1 2 [3]
31  Using Arduino / Programming Questions / Re: Button/ help on: February 27, 2012, 11:28:15 am
I feel I am close...
when compiling, it is not happy with the "break" portion..There is something with the "switch" that isn't jibing..
I tried to troubleshoot but now I'm a bit confused..
Can someone take a look? I know this is simple, but I am trying to learn!

Code:
int LED = 13;
int Button = 12;
int programState = 0;


void setup()
{

pinMode(LED,OUTPUT);
pinMode(Button,INPUT);
digitalWrite(Button,HIGH); //enable pull-up
}

void loop(){
if (digitalRead (Button)==0){ // assumes button declared as INPUT with internal pullup enabled
programState = programState +1;}
if (programState ==3){  // 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:

  digitalWrite(LED,HIGH);// basic blink
  delay (500);
  digitalWrite(LED,LOW);
  delay (500);
 
  break;
 


case 2:

  digitalWrite(LED,HIGH);//quicker blink
  delay (100);
  digitalWrite(LED,LOW);
  delay (100);
 
  break;
 
 
  case 3:


  digitalWrite(LED,LOW); //off

}
32  Using Arduino / Programming Questions / Re: Button/ help on: February 26, 2012, 05:53:18 pm
Thanks WildBill
I am grateful for all comments and help. I feel I know the "essence" of how to contruct the program in terms of logic, it is the details that get me..
Thanks again, let me digest, process and implement my new helpful comments...
I'll be back..
33  Using Arduino / Programming Questions / Button/ help on: February 26, 2012, 02:09:59 pm
I am a newbie, beginning to post more.. to learn more.
My first question about Momentary buttons is close to a solution but still far away.
The goal is to cycle through programs with the touch of a momentary button.
I am trying to learn and understand butI know something isn't jibing...
Any help would be greatly appreciated...
Code:
int LED = 13;
int Button = 12;
int programState = 0;


void setup()
{

pinMode(LED,OUTPUT);
pinMode(Button,INPUT);
}

void loop(){
if (digitalRead (Button)==0){ // assumes button declared as INPUT with internal pullup enabled
programState = programState +1;}
if (programState ==3){  // 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;

  digitalWrite(LED,HIGH);
  delay (500);
  digitalWrite(LED,LOW);
  delay (500);
 
  break;
 
switch(programState);

case 2;

  digitalWrite(LED,HIGH);
  delay (100);
  digitalWrite(LED,LOW);
  delay (100);
 
  break;
 
  switch(programState);
 
  case 3;

switch(programState);

  digitalWrite(LED,LOW);

}
34  Using Arduino / Programming Questions / Re: momentary button and programs on: February 21, 2012, 04:02:36 pm
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...
35  Using Arduino / Programming Questions / momentary button and programs on: February 21, 2012, 03:34:24 pm
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..
Pages: 1 2 [3]