|
int inpin1 = 13; //定义数字13接口
int val;//定义变量val
int buttonState1 = 0; //按键初始值为0
int beforeState1 = 0; //检测上一次按下是否松开
int k = 0; //光标位置
int j = 0; //光标位置
short i = 1;
void setup() {
Serial.begin(9600);
pinMode(inpin1, INPUT); //定义按键接口为输入接口
for (int yinjiao = 2; yinjiao < 13; yinjiao++)
{
pinMode(yinjiao, OUTPUT);
digitalWrite(yinjiao, HIGH);
}
}
void loop() {
val = digitalRead(inpin1); //读取数字13口电平值赋给val
buttonState1 = digitalRead(inpin1); //读取按键状态
if (buttonState1 == 1 and beforeState1 == 0) //如果按键按下并且上一次按下松开
{
switch (k)
{
case 1:
k = 0;
break;
case 0:
i++;
break;
}
}
if (buttonState1 != beforeState1) //消抖
{
delay(20);
}
beforeState1 = buttonState1;
Serial.println(i);
if (i >= 2 < 13)
{
digitalWrite(i, LOW);
}
else
{
i = 1;
}
}
-----------------------------------------------------------------------------------
上面是一个按键依次让(2-12)12个口低电平模式的程序。只能一直开下去,我想按键按到12下后
(2-12)口开始反转变为高电平。请问大神们,我该怎么改呢?谢谢啦
|
|