Skip to content

Instantly share code, notes, and snippets.

@c010
Created January 20, 2016 20:32
Show Gist options
  • Save c010/2c8001ffdf5595779a7b to your computer and use it in GitHub Desktop.
Save c010/2c8001ffdf5595779a7b to your computer and use it in GitHub Desktop.
Tut 1
// the input pin where the // pushbutton is connected
void button_light()
{
val = digitalRead(BUTTON); // read input value and store it
// check if there was a transition
if ((val == HIGH) && (old_val == LOW)) // when ever there is a change in state from button pressed
{
state = 1 - state;
delay(10); // delays before moving on in the code
}
old_val = val; // val is now old, let's store it
if (state == 1)
{
digitalWrite(LED, HIGH); // turn LED ON
}
else
{ digitalWrite(LED, LOW); // turn off led
}
}
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
}
}
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
}
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