Upload toggleSwitchbuttonSwitch.159.ino
Browse files
toggleSwitchbuttonSwitch.159.ino
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
int butPin=2;
|
| 2 |
+
int redPin=10;
|
| 3 |
+
int br=115200;
|
| 4 |
+
int butVal=1;
|
| 5 |
+
int butValOld=1;
|
| 6 |
+
int LEDstate=0;
|
| 7 |
+
int delayT=50;
|
| 8 |
+
|
| 9 |
+
void setup() {
|
| 10 |
+
// put your setup code here, to run once:
|
| 11 |
+
Serial.begin(br);
|
| 12 |
+
pinMode(redPin,OUTPUT);
|
| 13 |
+
pinMode(butPin,INPUT);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
void loop() {
|
| 17 |
+
// put your main code here, to run repeatedly:
|
| 18 |
+
butVal=digitalRead(butPin);
|
| 19 |
+
if (butValOld==0 && butVal==1){
|
| 20 |
+
if (LEDstate==0){
|
| 21 |
+
digitalWrite(redPin, HIGH);
|
| 22 |
+
}
|
| 23 |
+
if (LEDstate==1){
|
| 24 |
+
digitalWrite(redPin,LOW);
|
| 25 |
+
}
|
| 26 |
+
LEDstate=!LEDstate;
|
| 27 |
+
}
|
| 28 |
+
butValOld=butVal;
|
| 29 |
+
}
|