ARDUINO #500 INPUT OUTPUT ANALOG ไฟวิ่งกระพริบปรับความเร็วได้
28/12/2561 SONGCHAI PRAPATRUNGSEE
ARDUINO #500 INPUT OUTPUT ANALOG ไฟวิ่งกระพริบปรับความเร็วได้
int LED [] = {0,
1, 2, 3, 4, 5, 6, 7};//ARRAY
int VR = A5;//ANALOG
int VAL = analogRead(VR);//ANALOG
const int SW = 8;//SWICH
void setup() {
for (int i = 0; i < 8; i++)
pinMode (LED[i], OUTPUT);//OUTPUT
pinMode(SW, INPUT_PULLUP);//SWICH,INPUTPULLUP
}
void loop() {
if (digitalRead(SW) == HIGH) {
//SWICH
for (int i = 0; i < 8; i++)
{
VAL = analogRead(VR);//ANALOG
digitalWrite (LED[i], 1);//OUTPUT
delay(VAL);//MILLISECONDS
}
for (int i = 7; i >= 0;
i--) {
VAL = analogRead(VR);//ANALOG
digitalWrite (LED[i], 0);//OUTPUT
delay(VAL);//MILLISECONDS
}
}
if (digitalRead(SW) == LOW) { //SWICH
for (int i = 0; i < 8; i++)
{
VAL = analogRead(VR);//ANALOG
digitalWrite (LED[i], 1);
}
delay(VAL);
for (int i = 0; i < 8; i++)
{
VAL = analogRead(VR);//ANALOG
digitalWrite (LED[i], 0);//OUTPUT
}
delay(VAL);//MILLISECONDS
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น