I got 2 Push button, the first button selects divisibility of a number,
First button
1st Push - > Select to count divisibility of 2's
2nd Push -> Select to count divisibility of 5's
3rd Push -> Cancel
then the second button selects the number to start count
2nd Button
1st Push -> if 2's it starts to count from 0 - 2, if it 5's start to count from 0 - 5
2nd Push -> if 2's it starts to count from 0 - 4, if it 5's start to count from 0 - 10
3rd Push -> Cancel, back to First Button
there's no output in the serial monitor,
Thanks for the help.
void setup() {
Serial.begin(9600);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
}
void loop() {
PushButton1 ();
}
int PushButton1 () {
int Counter;
int State;
int LastState;
int pb1, pb2;
Counter = digitalRead(6);
if (State != LastState) {
if (State == LOW) {
Counter++;
Serial.println(Counter);
// Select to count divisible by 2's
if (Counter == 1) {
PushButton2 ();
menu (pb1, pb2);
}
// Select to count divisible by 5's
if (Counter == 2) {
PushButton2 ();
menu (pb1, pb2);
}
//cancel
if (Counter > 2) {
Counter = 0;
}
}
else {
}
delay(50);
}
LastState = State;
}
//2nd Button
int PushButton2 () {
int Counter;
int State;
int LastState;
int pb1, pb2;
Counter = digitalRead(7);
if (State != LastState) {
if (State == LOW) {
Counter++;
Serial.println(Counter);
if (Counter == 1) {
menu (pb1, pb2);
}
if (Counter == 2) {
menu (pb1, pb2);
}
//cancel
if (Counter > 2) {
Counter = 0;
}
}
else {
}
delay(50);
}
LastState = State;
}
void menu (int pb1, int pb2) {
switch (pb1) {
case 0: switch (pb2) {
case 0: twocounts ();
break;
case 1: fourcounts ();
break;
}
break;
case 1: switch (pb2) {
case 0: fivecounts ();
break;
case 1: tencounts ();
break;
}
break;
}
}
void twocounts () {
for (int x = 0; x > 3 ; x++) {
Serial.print(x);
delay(100);
}
}
void fourcounts () {
for (int x = 0; x > 5 ; x++) {
Serial.print(x);
delay(100);
}
}
void tencounts () {
for (int x = 0; x > 11 ; x++) {
Serial.print(x);
delay(100);
}
}
void fivecounts () {
for (int x = 0; x > 6 ; x++) {
Serial.print(x);
delay(100);
}
}