Permalink
Browse files

Add continuous mode

  • Loading branch information...
1 parent 7c1bd10 commit cc252a3feb19c9b10554df09d65c6364f2d73582 Luke Closs committed Jan 24, 2011
Showing with 42 additions and 3 deletions.
  1. +42 −3 space_displayduino/vhsduino.c
@@ -4,13 +4,27 @@
#define rPin2 3
#define gPin2 4
#define bPin2 12
+#define speedPot 3
#define rPot 2
#define gPot 1
#define bPot 0
#define toilet 2
+// State for the colour change system
+int desired_r = 0;
+int desired_g = 0;
+int desired_b = 0;
+int previous_r = 0;
+int previous_g = 0;
+int previous_b = 0;
+int actual_r = 0;
+int actual_g = 0;
+int actual_b = 0;
+unsigned long last_change = 0;
+
int flush_idle_state;
void setup() {
+ last_change = millis();
pinMode(rPin1, OUTPUT); analogWrite(rPin1, 0);
pinMode(gPin1, OUTPUT); analogWrite(gPin1, 0);
pinMode(bPin1, OUTPUT); analogWrite(bPin1, 0);
@@ -33,6 +47,9 @@ void write_both_leds (int r, int g, int b) {
// best.
write_west_leds(r, g, b);
write_east_leds(r, g, b);
+ actual_r = r;
+ actual_g = g;
+ actual_b = b;
}
#define white_max 100
@@ -47,14 +64,36 @@ void soothing_flushing_motion (void) {
}
void loop() {
- int flushing = digitalRead(toilet);
- if (flush_idle_state != flushing) {
+ int is_flushing = digitalRead(toilet);
+ int speed = analogRead(speedPot); // 0 to 1023
+ if (flush_idle_state != is_flushing) {
soothing_flushing_motion();
}
+ else if (speed > 10) {
+ unsigned long time_interval = speed * 10;
+ unsigned long now = millis();
+ unsigned long next_change = last_change + time_interval;
+
+ if (now > next_change) {
+ // time to change the desired
+ desired_r = random(255);
+ desired_g = random(255);
+ desired_b = random(255);
+ previous_r = actual_r;
+ previous_g = actual_g;
+ previous_b = actual_b;
+ last_change = now;
+ }
+
+ float percent = ((float) (now - last_change)) / time_interval;
+ int r_change = (desired_r - previous_r) * percent;
+ int g_change = (desired_g - previous_g) * percent;
+ int b_change = (desired_b - previous_b) * percent;
+ write_both_leds(previous_r + r_change, previous_g + g_change, previous_b + b_change);
+ }
else {
write_both_leds(analogRead(rPot) / 4,
analogRead(bPot) / 4,
analogRead(gPot) / 4);
}
}
-

0 comments on commit cc252a3

Please sign in to comment.