Skip to content

Instantly share code, notes, and snippets.

@alexBaizeau
Last active August 29, 2015 14:00
Show Gist options
  • Save alexBaizeau/11357750 to your computer and use it in GitHub Desktop.
Save alexBaizeau/11357750 to your computer and use it in GitHub Desktop.
#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