#include <CD74HC4067.h>

const int button1Pin = 7; // 你的button1引脚
CD74HC4067 mux(4, 5, 6, 11);  // 修改为不冲突的引脚配置,比如使用引脚 11

int ledCount = 3; // 三个LED
int currentLed = 0; // 当前LED

bool button1Pressed = false; // 记录button1的按下状态

void setup() {
  pinMode(button1Pin, INPUT);

  // 打开LED1
  mux.channel(0);
  digitalWrite(A0, HIGH);  // 切换到共享的引脚
  delay(100);

  // 初始化其他LED
  for (int i = 1; i < ledCount; ++i) {
    mux.channel(i);
    digitalWrite(A0, LOW);  // 切换到共享的引脚
    delay(100);
  }
}

void loop() {
  bool button1State = digitalRead(button1Pin);

  if (button1State == HIGH && !button1Pressed) {
    // 按钮按下
    button1Pressed = true;

    // 关闭当前LED
    mux.channel(currentLed);
    digitalWrite(A0, LOW);  // 切换到共享的引脚
    delay(100);

    // 切换到下一个LED
    currentLed = (currentLed + 1) % ledCount;

    // 打开新LED
    mux.channel(currentLed);
    digitalWrite(A0, HIGH);  // 切换到共享的引脚
    delay(100);
  } else if (button1State == LOW && button1Pressed) {
    // 按钮抬起
    button1Pressed = false;
  }
}
Loading
cd74hc4067