-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggleSwitch.ino
More file actions
34 lines (33 loc) · 839 Bytes
/
Copy pathtoggleSwitch.ino
File metadata and controls
34 lines (33 loc) · 839 Bytes
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
30
31
32
33
34
int ReadButton=12;// since am reading digital signal from the Arduino the
//readPin must be connectedtothe pin with s sign infront
int ledPin=9;
int buttonNew;
int timeDelay=1000;
//int buttonState1;
int buttonOld=1;
int LedState=0 ;
void setup() {
// put your setup code here, to run once:
pinMode(ReadButton,INPUT);
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
buttonNew=digitalRead(ReadButton);//value read from th board(1 or 0)
Serial.println(buttonNew);
delay(timeDelay);
//This SWITCH ON the Led or SWITCH OFF the LED
if (buttonNew==1 && buttonOld==0){
if (LedState==0){
digitalWrite(ledPin,HIGH);
LedState=1;
}
else{
digitalWrite(ledPin,LOW);
LedState=0;
}
}
buttonOld=buttonNew ;
delay(timeDelay);
}