欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Mixly按键控制LED灯

程序员文章站 2022-06-20 12:15:25
...

实现米思齐按键控制LED(改写方法3)

volatile boolean b1;
volatile boolean b2;
volatile byte click;
volatile boolean lastState;
volatile boolean toggle;

void setup(){
  lastState = LOW;
  toggle = LOW;
  click = 0;
  b1 = 0;
  b2 = 0;
  pinMode(8, INPUT);
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  digitalWrite(13,HIGH);
  pinMode(8, INPUT_PULLUP);
  lastState = digitalRead(8);
}

void loop(){
  Serial.println(digitalRead(8));
  b1 = digitalRead(8);
  if (b1 != lastState) {
    delay(20);
    b2 = digitalRead(8);
    if (b2 == b1) {
      lastState = b1;
      click = click + 1;

    }

  }
  if (click == 2) {
    click = 0;
    toggle = !toggle;
    digitalWrite(13,toggle);

  }

}

mixly拼图

Mixly按键控制LED灯

结果:

https://v.youku.com/v_show/id_XNDQwNzQzMTI4OA==.html?x&sharefrom=android&sharekey=351052bd66db467b723dbe96082d4da15