Selected Courses on Digital Art-UOWM

14 Νοεμβρίου 2014

arduino 02

Filed under: ARDUINO — admin @ 11:09
HIGH (there is voltage here)  AND LOW(there is no voltage here)
digitalWrite()

PINS

int switchState = 0;

void setup()
{

  pinMode (3, OUTPUT);
  pinMode (4, OUTPUT);
  pinMode (5, OUTPUT);
  pinMode (2, INPUT); //This pin is the button as INPUT.
}

void loop()
{
  switchState = digitalRead(2); //switchState will change to HIGH(1) or LOW(0) depending if the button is pressed.

  if (switchState==LOW) { //If the button is not pressed.
 
    digitalWrite (3, HIGH); //green LED will be on.
    digitalWrite (4, LOW);
    digitalWrite (5, LOW);
  }

  else { //else is applied only if the corresponding “if” state isn’t accomplished.
 
    digitalWrite (3, LOW);
    digitalWrite (4, LOW);
    digitalWrite (5, HIGH);
 
    delay(250);// wait for a quarter second
   //toogle the Leds
    digitalWrite (4, HIGH);
    digitalWrite (5, LOW);
    delay (250);// wait for a quarter second
  }

}

Δεν υπάρχουν Σχόλια »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

error: Content is protected !!