|
本帖最后由 topdog 于 2021-3-29 22:30 编辑
1,按钮1选择LED,
2,按钮2闪烁步骤1选择的LED,
3,按钮3全亮或全灭所有LED。
图画好了,才看到附加的第三个按钮,接A2吧,偷懒一下不修改线路图了。
[pre]//https://www.arduino.cn/thread-103433-1-1.html
int buttonpin[] = {A0, A1, A2};
int ledpin[] = {8, 9, 10};
bool allled = false;
void setup()
{
Serial.begin(9600);
for (int i = 0; i < 3; i++)
{
pinMode(ledpin, OUTPUT);
pinMode(buttonpin, INPUT);
}
}
void loop()
{
int numberled;
bool status_button1 = digitalRead(buttonpin[0]);
bool status_button2 = digitalRead(buttonpin[1]);
bool status_button3 = digitalRead(buttonpin[2]);
if (status_button1 == true) {
numberled += 1;
}
if (numberled = 3) numberled = 0;
if (status_button2 == true) {
digitalWrite(ledpin[numberled], HIGH);
delay(100);
digitalWrite(ledpin[numberled], LOW);
delay(100);
}
if (status_button3 == true) {
for (int j = 0; j < 3; j++)
{
digitalWrite(ledpin[j], allled);
delay(100);
}
allled = !allled;
}
}[/pre] |
|