Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ATTINY 45 RGB LED FOR THE BLING THING
- */
- const int buttionPin=4; //create and name button pin
- int buttonState=0; //current state of button
- int lastButtonState=0; //previous state of button
- int state = 0; // 0 = lights out, 1 = run light show
- int redPin = 0;
- int greenPin = 1;
- int bluePin = 3;
- void setup()
- {
- pinMode(buttonPin,INPUT);
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- }
- void loop()
- {
- buttonState=digitalRead(buttonPin); //read input store
- if ((buttonState == HIGH) && (lastButtonState == LOW)){
- state = 1 - state;
- delay = (10);
- }
- lastButtonState = buttonState; //store old button value
- if (state == 1) {
- lightShow();
- }
- esle
- {
- noShow();
- }
- }
- void lightShow(){
- setColor(255, 0, 0); // red
- delay(1000);
- setColor(0, 255, 0); // green
- delay(1000);
- setColor(0, 0, 255); // blue
- delay(1000);
- setColor(255, 255, 0); // yellow
- delay(1000);
- setColor(128, 0, 128); // purple
- delay(1000);
- setColor(0, 255, 255); // aqua
- delay(1000);
- setColor(128, 128, 0); //olive
- delay(1000);
- setColor(0, 128, 128); //teal
- delay(1000);
- }
- void noShow(){
- setColor(0, 0, 0); //lights out
- void setColor(int red, int green, int blue)
- {
- analogWrite(redPin, red);
- analogWrite(greenPin, green);
- analogWrite(bluePin, blue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement