1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| boolean pushButton1; boolean pushButton2; int ledpin=9; int brightness=128; void setup() { pinMode(2,INPUT_PULLUP); pinMode(8,INPUT_PULLUP); pinMode(ledpin,OUTPUT); Serial.begin(9600); }
void loop() { pushButton1=digitalRead(2); pushButton2=digitalRead(8); if(!pushButton1 && brightness > 0) { brightness--; } if(!pushButton2 && brightness < 255) { brightness++; } analogWrite(ledpin,brightness); Serial.println(brightness); delay(10); }
|