Advertisement
ossipee

buttons

May 19th, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1.   /*
  2.     ATTINY 45 RGB LED FOR THE BLING THING
  3.     */
  4.     const int buttionPin=4;  //create and name button pin
  5.     int buttonState=0;      //current state of button
  6.     int lastButtonState=0; //previous state of button
  7.     int state = 0;         // 0 = lights out, 1 = run light show
  8.     int redPin = 0;
  9.     int greenPin = 1;
  10.     int bluePin = 3;
  11.      
  12.     void setup()
  13.     {
  14.     pinMode(buttonPin,INPUT);
  15.     pinMode(redPin, OUTPUT);
  16.     pinMode(greenPin, OUTPUT);
  17.     pinMode(bluePin, OUTPUT);
  18.     }
  19.      
  20.     void loop()
  21.     {
  22.     buttonState=digitalRead(buttonPin); //read input store
  23.     if ((buttonState == HIGH) && (lastButtonState == LOW)){
  24.     state = 1 - state;
  25.     delay = (10);
  26.     }
  27.     lastButtonState = buttonState; //store old button value
  28.     if (state == 1) {
  29.     lightShow();
  30.      }
  31.      esle
  32.      {
  33.       noShow();
  34.      }
  35.     }
  36.     void lightShow(){
  37.    
  38.     setColor(255, 0, 0); // red
  39.     delay(1000);
  40.     setColor(0, 255, 0); // green
  41.     delay(1000);
  42.     setColor(0, 0, 255); // blue
  43.     delay(1000);
  44.     setColor(255, 255, 0); // yellow
  45.     delay(1000);
  46.     setColor(128, 0, 128); // purple
  47.     delay(1000);
  48.     setColor(0, 255, 255); // aqua
  49.     delay(1000);
  50.     setColor(128, 128, 0); //olive
  51.     delay(1000);
  52.     setColor(0, 128, 128); //teal
  53.     delay(1000);
  54.     }
  55.    
  56.     void noShow(){
  57.       setColor(0, 0, 0); //lights out
  58.      
  59.     void setColor(int red, int green, int blue)
  60.     {
  61.     analogWrite(redPin, red);
  62.     analogWrite(greenPin, green);
  63.     analogWrite(bluePin, blue);
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement