Created
December 10, 2016 13:04
-
-
Save GreenMoonArt/10486399f9285e3881204bfe6931be17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// move servo in between RGB LED updates | |
#include <Servo.h> | |
Servo servo; | |
const int servoRestPosition = 0; //Starting position | |
const int servo90Position = 90; //90 degrees | |
const int servoTargetPosition = 180; //Position when event is detected | |
#define GREEN 3 | |
#define BLUE 5 | |
#define RED 6 | |
#define delayTime 20 | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("start"); | |
servo.attach(9); | |
servo.write(servoRestPosition); | |
//servo.detach(); | |
analogWrite(RED, 0); | |
analogWrite(GREEN, 0); | |
analogWrite(BLUE, 0); | |
delay(250); | |
} | |
void loop() { | |
servo.write(servoRestPosition); | |
int redVal = 255; | |
int blueVal = 0; | |
int greenVal = 0; | |
for ( int i = 0 ; i < 255 ; i += 1 ) | |
{ | |
greenVal += 1; | |
redVal -= 1; | |
analogWrite(GREEN, 255 - greenVal ); | |
analogWrite(RED, 255 - redVal ); | |
delay( delayTime ); | |
} | |
servo.write(servo90Position); | |
redVal = 0; | |
blueVal = 0; | |
greenVal = 255; | |
for ( int i = 0 ; i < 255 ; i += 1 ) | |
{ | |
blueVal += 1; | |
greenVal -= 1; | |
analogWrite(BLUE, 255 - blueVal ); | |
analogWrite(GREEN, 255 - greenVal ); | |
delay( delayTime ); | |
} | |
servo.write(servoTargetPosition); | |
redVal = 0; | |
blueVal = 255; | |
greenVal = 0; | |
for ( int i = 0 ; i < 255 ; i += 1 ) | |
{ | |
redVal += 1; | |
blueVal -= 1; | |
analogWrite(RED, 255 - redVal ); | |
analogWrite(BLUE, 255 - blueVal ); | |
delay( delayTime ); | |
} | |
} //loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment