Here is an image of my completed circuit:
Here are 2 video's of the switches, notice they have different functions simply by making simple alterations to the code:
And finally here is the code used for the circuit:
int ledPin = 13; // choose the pin for the LED
int inPin = 2; //choose the input pin (for a pushbutton)
int ledPin2 = 10;
int inPin2 = 3;
int val = 0; //variable for reading the pin status
int val2 = 0;
void setup() {
pinMode (ledPin, OUTPUT); //declare LED as output
pinMode (inPin, INPUT); //declare pushbutton as input
pinMode (ledPin2, OUTPUT); //declare LED as output
pinMode (inPin2, INPUT); //declare pushbutton as input
}
void loop() {
val = digitalRead(inPin); //read input value
if (val == HIGH) { //check if the input is HIGH (button Released)
digitalWrite (ledPin, LOW); //turn LED OFF
} else
digitalWrite (ledPin, HIGH); //turn LED ON
val2 = digitalRead(inPin2); //read input value
if (val2 == HIGH) { //check if the input is HIGH (button Released)
digitalWrite (ledPin2, LOW); //turn LED OFF
} else
digitalWrite (ledPin2, HIGH); //turn LED ON
}
No comments:
Post a Comment