Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define RED 7
- #define BLUE 6
- #define GREEN 5
- #define R_BUTTON 2
- #define G_BUTTON 1
- #define B_BUTTON 0
- int rFlag = 0;
- int gFlag = 0;
- int bFlag = 0;
- bool rState = true;
- bool gState = true;
- bool bState = true;
- void setup() {
- pinMode(RED, OUTPUT);
- pinMode(GREEN, OUTPUT);
- pinMode(BLUE, OUTPUT);
- pinMode(R_BUTTON, INPUT_PULLUP);
- pinMode(G_BUTTON, INPUT_PULLUP);
- pinMode(B_BUTTON, INPUT_PULLUP);
- }
- void loop() {
- digitalWrite(RED, rFlag);
- digitalWrite(GREEN, gFlag);
- digitalWrite(BLUE, bFlag);
- if ((digitalRead(R_BUTTON) == LOW) && rState) {
- rFlag = (rFlag + 1) % 2;
- rState = false;
- } else if (digitalRead(R_BUTTON) == HIGH) {
- rState = true;
- }
- if ((digitalRead(G_BUTTON) == LOW) && gState) {
- gFlag = (gFlag + 1) % 2;
- gState = false;
- } else if (digitalRead(G_BUTTON) == HIGH) {
- gState = true;
- }
- if ((digitalRead(B_BUTTON) == LOW) && bState) {
- bFlag = (bFlag + 1) % 2;
- bState = false;
- } else if (digitalRead(B_BUTTON) == HIGH) {
- bState = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement