Last active
August 29, 2015 14:00
-
-
Save alexBaizeau/11357750 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
#define REDPIN 3 | |
#define GREENPIN 5 | |
#define BLUEPIN 6 | |
#define MOTION 2 | |
int green[] = {0, 255, 0}; | |
int red[] = {255, 0, 0}; | |
int off[] = {0, 0, 0}; | |
void setup() { | |
pinMode(REDPIN, OUTPUT); | |
pinMode(GREENPIN, OUTPUT); | |
pinMode(BLUEPIN, OUTPUT); | |
pinMode(MOTION, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if(!(digitalRead(MOTION))){ | |
//blink red 10 time | |
for (int i =0; i<10; i++) { | |
writeRGB(red); | |
delay(100); | |
writeRGB(off); | |
delay(100); | |
} | |
} | |
writeRGB(green); | |
} | |
/** | |
* Set an RGB colour | |
* | |
* @param int *rgb an array of rgb values | |
*/ | |
void writeRGB(int *rgb){ | |
analogWrite(REDPIN, rgb[0]); | |
analogWrite(GREENPIN, rgb[1]); | |
analogWrite(BLUEPIN, rgb[2]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment