|
本帖最后由 bingshao1006 于 2015-7-4 16:16 编辑
用三个按键来做上、下、确定按钮,并将现在的数值通过串口打印出来。
但是这个程序调试了半天都没调出来,哪位能否帮忙看一下?
程序代码如下:- int choose_UP_pin = 2;
- int choose_DOWN_pin = 3;
- int ENTER_pin = 4;
- int State_Key = 1;
- boolean choose_UP = LOW;
- boolean choose_DOWN = LOW;
- boolean ENTER = LOW;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(choose_UP_pin,INPUT);
- pinMode(choose_DOWN_pin,INPUT);
- pinMode(ENTER_pin,INPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- choose_UP = digitalRead(choose_UP_pin);
- if(choose_UP == HIGH)
- {
- State_Key++;
- if(State_Key == 11)
- {
- State_Key = 1;
- }
- while(digitalRead(choose_UP_pin) == HIGH);
- }
- choose_DOWN = digitalRead(choose_DOWN_pin);
- if(choose_DOWN == HIGH)
- {
- State_Key--;
- if(State_Key == 0)
- {
- State_Key = 10;
- }
- while(digitalRead(choose_DOWN_pin) == HIGH);
- }
- ENTER = digitalRead(ENTER_pin);
- if(ENTER == HIGH)
- {
- Serial.write(State_Key);
- while(digitalRead(ENTER_pin) == HIGH);
- }
- }
复制代码 |
|