matt1eg
Joined: 05 Feb 2009 Posts: 14
|
IF statement and push buttons |
Posted: Wed Mar 18, 2009 7:01 pm |
|
|
Hi
I think I'm just being stupid but I can't get a sub-routine to work as I need it. It is meant to detect what button is pushed and then do something accordingly. All works except one statement. This is the last else if Code: | else if(!input(CANCEL)){
printf(lcd_putc,"\f\n ARE YOU SURE?");
printf(lcd_putc,"\n\nYES = SEL NO = CAN");
delay_ms(200);
if(!input(SELECT)){
printf(lcd_putc,"\f\n CANCELLED");
delay_ms(1600);
break;
}
else if(!input(CANCEL)){
continue;
delay_ms(250);
}
} |
When either button is pressed it doesnt do the action in the sub if and else but the action of the button in the while loop. The code is below which should help me make sense more
Code: | void Set_Tariff()
{
delay_ms(100);
Tariff = 0;
printf(lcd_putc,"\f ENTER TARIFF\n",);
printf(lcd_putc,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06);
printf(lcd_putc," %2.1fp PER UNIT\n",tariff);
printf(lcd_putc,"\nMORE = + LESS = -");
while(Tariff_Set==FALSE){
if(!input(INCREMENT)){ //This Works fine
Tariff += 0.5;
delay_ms(200);
printf(lcd_putc,"\f ENTER TARIFF\n");
printf(lcd_putc,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06);
printf(lcd_putc," %2.1fp PER UNIT",tariff);
printf(lcd_putc,"\n\nYES = SEL NO = CAN");
}
else if(!input(DECREMENT)){ //This Works fine
Tariff -= 0.5;
delay_ms(200);
printf(lcd_putc,"\f ENTER TARIFF\n");
printf(lcd_putc,"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06);
printf(lcd_putc," %2.1fp PER UNIT",tariff);
printf(lcd_putc,"\n\nYES = SEL NO = CAN");
}
else if(!input(SELECT)){ //This Works fine
Tariff_Set = TRUE;
delay_ms(200);
}
else if(!input(CANCEL)){ // This is the Problem
printf(lcd_putc,"\f\n ARE YOU SURE?");
printf(lcd_putc,"\n\nYES = SEL NO = CAN");
delay_ms(200);
if(!input(SELECT)){
printf(lcd_putc,"\f\n CANCELLED"); //If I press 'select' it does the previous statement
delay_ms(1600);
break;
}
else if(!input(CANCEL)){ //Same kind of issue here
continue;
delay_ms(250);
}
}
}
} |
I'm sure its just my fairley basic knowledge of C but I don't know a way around it or to sort it.
Any suggestions welcome
Cheers |
|