I am having some problems with pushbuttons on my board. I have a Codepiece which should write increment a value and show it on the LCD, when i press the button. For some reason does this code only work for one button on my board. When i change the input to another button, it starts at the state where the button is high, and then goes back to low. It increments the value once at the start, without the button being pressed. But it reacts correctly when i press the button. code attached
:
Moved by Admin
John Mayer wrote: > I have a Codepiece Unfortunately we don't have this code - and without it its impossible to tell what goes wrong. Please post the code or attach it.
Code here Buttonleft and buttonright increment the value when it's beeing pressed, but buttondown is the problem. the value gets incremented once eventhough the button hasn't been pressed. switch(state) { case 0: if(buttonright_pressed()) // -- right { state= 1; } if(buttondown_pressed()) // left { state= 4; } if(buttonleft_pressed()) { state = 5; } break; //-----------------------------------------------------------// case 1: if(!(buttonright_pressed())) { buttom_timer = TIM_100_MSEC; state = 3; } break; case 4: if(!(buttondown_pressed())) { buttom_timer = TIM_100_MSEC; state = 2; } break; case 5: if(!(buttonleft_pressed())) { buttom_timer = TIM_100_MSEC; state = 6; } break; //------------------------------------------------------------// case 2: if(!--buttom_timer) { tx_cmd = 1; xQueueSend(Queue1,&tx_cmd,0); tx_cmd = 0; state = 0; } break; case 3: if(!--buttom_timer) { tx_cmd = 2; xQueueSend(Queue1,&tx_cmd,0); tx_cmd = 0; state = 0; } break; case 6: if(!--buttom_timer) { tx_cmd = 3; xQueueSend(Queue1,&tx_cmd,0); tx_cmd = 0; state = 0; } break; }
:
Edited by User