Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define RED_PIN 11
- #define BLUE_PIN 10
- #define GREEN_PIN 9
- #define RED_BUT_PIN 4
- #define BLUE_BUT_PIN 3
- #define GREEN_BUT_PIN 2
- void setup(){
- pinMode(RED_PIN, OUTPUT);
- pinMode(BLUE_PIN, OUTPUT);
- pinMode(GREEN_PIN, OUTPUT);
- pinMode(RED_BUT_PIN, INPUT_PULLUP);
- pinMode(BLUE_BUT_PIN, INPUT_PULLUP);
- pinMode(GREEN_BUT_PIN, INPUT_PULLUP);
- }
- int red = 0;
- int blue = 0;
- int green = 0;
- boolean redWasUp = true;
- boolean blueWasUp = true;
- boolean greenWasUp = true;
- void loop(){
- Control(red, redWasUp, RED_PIN, RED_BUT_PIN);
- Control(blue, blueWasUp, BLUE_PIN, BLUE_BUT_PIN);
- Control(green, greenWasUp, GREEN_PIN, GREEN_BUT_PIN);
- }
- void Control(int &color, boolean &wasUp, int colorPin, int butPin){
- if(handleClick(butPin, wasUp)){
- if(color == 0)
- color = 255;
- else
- color = 0;
- analogWrite(colorPin, color);
- }
- }
- boolean handleClick(int buttonPin, boolean wasUp){
- boolean isUp = digitalRead(buttonPin);
- if (wasUp && !isUp){
- delay(10);
- isUp = digitalRead(buttonPin);
- }
- if(isUp && !isUp){
- delay(10);
- isUp = digitalRead(buttonPin);
- return !isUp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement