Multiple button press choices
hi,
i still new programming , have trawled through pages of example code trying find similar want achieve can't quite work out.
i using dueminalove motor shield/stepper motor. have 4 push switches, let's named setupa, setupb, starta, startb.
the end objective have stepper motor, on pushing relevant switch (setupa or b), move 1 of 2 starting positions wait relevent start switch pressed (starta or b) run through different motor sequences.
code-wise trying achieve-
on power want code wait input either setupa or setupb switches.
when either pressed runs relevent bit of code, setupcodea or setupcodeb, (getting motor 1 of 2 start positions)
then after running relevant code waits input starta or startb switch
when start or b button pressed runs either startcodea or startcodeb (starting motor on 1 of 2 start sequences)
i trying work out statements use achieve or 'call' different bits of code wait. understanding may need use switch/case statement don't quite understand how implement in case.
i don't have problems rest of setup, 'using different switches run different code' confusing me.
any or pointers similar appreciated.
i still new programming , have trawled through pages of example code trying find similar want achieve can't quite work out.
i using dueminalove motor shield/stepper motor. have 4 push switches, let's named setupa, setupb, starta, startb.
the end objective have stepper motor, on pushing relevant switch (setupa or b), move 1 of 2 starting positions wait relevent start switch pressed (starta or b) run through different motor sequences.
code-wise trying achieve-
on power want code wait input either setupa or setupb switches.
when either pressed runs relevent bit of code, setupcodea or setupcodeb, (getting motor 1 of 2 start positions)
then after running relevant code waits input starta or startb switch
when start or b button pressed runs either startcodea or startcodeb (starting motor on 1 of 2 start sequences)
i trying work out statements use achieve or 'call' different bits of code wait. understanding may need use switch/case statement don't quite understand how implement in case.
i don't have problems rest of setup, 'using different switches run different code' confusing me.
any or pointers similar appreciated.
pretty basic stuff there:
} // end loop
code: [select]
byte setupaswitch = 2;// define pins used
byte setupbswitch = 3;
byte startaswitch = 4;
byte startbswitch = 5;
byte mode; // 0 = waiting start, 1 = setupa, 2 = setupb, 3 = post setup, pre-startup, 4 = code, 5 = bcode, 6 = post a/b startup code
void setup(){
pinmode (setupaswitch, input);
digitalwrite (setupaswitch, high); // turn on internl pullup - check low input indicate switch closed ground
pinmode (setupbswitch, input);
digitalwrite (setupbswitch, high);
pinmode (startaswitch, input);
digitalwrite (startaswitch, high);
pinmode (startbswitch, input);
digitalwrite (startbswitch, high);
void loop(){
if (mode ==0 && digitalread(setupaswitch) == low){ mode = 1;}
if (mode == 0 && digitalread(setupbswitch_ == low) {mode = 2;}
if ( mode == 3 && digitalread (startaswitch) == low){ mode = 4;}
if ( mode == 3 && digitalread (startbswitch) == low){ mode = 5;}
switch (mode){
case 0:
// nothing
break;
case 1:
// setup code
mode = 3;
break;
case 2:
// b setup code
mode = 3;
break;
case 3:
// nothing
break;
case 4:
// start code
mode = 6;
break;
case 5:
// b start code
mode = 6;
break;
case 6:
// whatever done after setup & start
break;
} // end switch
} // end loop
Arduino Forum > Using Arduino > Programming Questions > Multiple button press choices
arduino
Comments
Post a Comment