Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int RED=4;
- const int GREEN=0;
- const int BLUE=1;
- const int SENSE=3;
- const int threshold=4;
- const int rate=120;
- boolean dark=false;
- float cycle_time=float(rate)*768/3600000.0; //rate*768 is ms in rainbow, 3600000.0 is ms in hour
- float timeout_hours=8; //must be divided by x.0 (e.g. "1/15.0")to get accurate result if not an integer
- int cycles_to_run=int(timeout_hours/cycle_time)+1;
- int cycle_counter=0;
- void setup() {
- pinMode(RED,OUTPUT);
- pinMode(GREEN,OUTPUT);
- pinMode(BLUE,OUTPUT);
- changeColor(0,0,0);
- }
- void loop() {
- if ((analogRead(SENSE)<threshold)&&(!dark)) {
- dark=true;
- }
- else if ((analogRead(SENSE)>=threshold)&&(dark)) {
- dark=false;
- cycle_counter=0;
- }
- if ((dark)&&(cycle_counter<cycles_to_run)) {
- for (int i=0;i<256;i++) {
- changeColor(255-i,i,0);
- delay(rate);
- }
- for (int j=0;j<256;j++) {
- changeColor(0,255-j,j);
- delay(rate);
- }
- for (int k=0;k<256;k++) {
- changeColor(k,0,255-k);
- delay(rate);
- }
- cycle_counter++;
- }
- else {
- changeColor(0,0,0);
- delay(50);
- }
- }
- void changeColor(int r,int g,int b) {
- analogWrite(RED,255-r);
- analogWrite(GREEN,255-g);
- analogWrite(BLUE,255-b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement