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 DELTA 3
- void setup(){
- pinMode(BLUE_PIN, OUTPUT);
- pinMode(RED_PIN, OUTPUT);
- pinMode(GREEN_PIN, OUTPUT);
- }
- int blue = 0;
- boolean blueWasOn = false;
- int red = 0;
- boolean redWasOn = true;
- int green = 0;
- boolean greenWasOn = false;
- void loop(){
- if(blue < 255 && !blueWasOn){
- Plus(blue, blueWasOn, BLUE_PIN, redWasOn);
- Minus(green, greenWasOn, GREEN_PIN);
- }
- if(red < 255 && !redWasOn){
- Plus(red, redWasOn, RED_PIN, greenWasOn);
- Minus(blue, blueWasOn, BLUE_PIN);
- }
- if(green < 255 && !greenWasOn){
- Plus(green, greenWasOn, GREEN_PIN, blueWasOn);
- Minus(red, redWasOn, RED_PIN);
- }
- }
- void Plus(int &color, boolean &colorWasOn, int pin, boolean &prePreColorWasOn){
- color = constrain(color + DELTA, 0, 255);
- if(color >= 252){
- colorWasOn = !colorWasOn;
- color = 255;
- prePreColorWasOn = false;
- }
- analogWrite(pin, color);
- delay(25);
- }
- void Minus(int &preColor, boolean &preColorWasOn, int prePin){
- preColor = constrain(preColor - DELTA, 0, 255);
- if(preColor <= 3){
- preColor = 0;
- preColorWasOn = true;
- }
- analogWrite(prePin, preColor);
- delay(25);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement