Advertisement
ossipee

buttons compiles

May 19th, 2014
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. /*
  2.     ATTINY 85 RGB LED FOR THE BLING THING by ossipee :D
  3.     */
  4.     const int buttonPin=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(redPin, OUTPUT);
  15.     pinMode(greenPin, OUTPUT);
  16.     pinMode(bluePin, OUTPUT);
  17.     }
  18.      
  19.     void loop()
  20.     {
  21.     buttonState=digitalRead(buttonPin); //read input store
  22.     if ((buttonState == HIGH) && (lastButtonState == LOW)){
  23.     state = 1 - state;
  24.     delay(10);
  25.     }
  26.     lastButtonState = buttonState; //store old button value
  27.     if (state == 1) {
  28.     lightShow();
  29.      }
  30.      else
  31.      {
  32.       noShow();
  33.      }
  34.     }
  35.     void lightShow(){
  36.    
  37.     setColor(255, 0, 0); // red
  38.     delay(1000);
  39.     setColor(0, 255, 0); // green
  40.     delay(1000);
  41.     setColor(0, 0, 255); // blue
  42.     delay(1000);
  43.     setColor(255, 255, 0); // yellow
  44.     delay(1000);
  45.     setColor(128, 0, 128); // purple
  46.     delay(1000);
  47.     setColor(0, 255, 255); // aqua
  48.     delay(1000);
  49.     setColor(128, 128, 0); //olive
  50.     delay(1000);
  51.     setColor(0, 128, 128); //teal
  52.     delay(1000);
  53.     }
  54.    
  55.     void noShow(){
  56.       setColor(0, 0, 0); //lights out
  57.     }
  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