Created
January 20, 2016 20:32
-
-
Save c010/2c8001ffdf5595779a7b to your computer and use it in GitHub Desktop.
Tut 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void change_lights() | |
{ | |
val = digitalRead(BUTTON); // read input value and store it | |
// check if there was a transition | |
if ((val == HIGH) && (old_val == LOW) ) | |
{ | |
state = 1 - state; | |
delay(10); | |
} | |
old_val = val; // val is now old, let's store it | |
if (state == 1) | |
{ | |
digitalWrite(LED, HIGH); // turn LED1 ON | |
digitalWrite(LED2, LOW); // turn LED2 off | |
} | |
else | |
{ | |
digitalWrite(LED, LOW); // turn LED1 off | |
digitalWrite(LED2, HIGH); // turn LED2 ON | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void flashing_light() | |
{ | |
digitalWrite(LED, HIGH); // turn on led | |
delay(1000); // time that it is on | |
digitalWrite(LED, LOW); // turns off led | |
delay(1000); // time that is off | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int LED = 13; // LED connected to pin 13 | |
const int LED2 = 12; | |
const int BUTTON = 7; | |
int val=0; // val will be used to store the state // of the input pin | |
int old_val = 0; // this variable stores the previous // value of "val" | |
int state = 0; // 0 = LED off and 1 = LED on | |
void setup() { | |
pinMode(LED, OUTPUT); // sets the led is an output source | |
pinMode(BUTTON, INPUT); // and BUTTON is an input | |
pinMode(LED2, OUTPUT); | |
} void loop() { | |
// flashing_light(); // goes to function of this name | |
//button_light(); // goes to function of this name | |
change_lights(); // goes to function of this name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment