Monday, October 15, 2007

editing and prototyping the midterm design


We've been tailoring our bike reflector design a little bit, and here are some changes. Once the LEDs are turned on and powered up, it would be cool to have a sequencer triggering the lights, so that cars coming from behind the bike rider at night will see movement, perhaps causing them to be more careful with their speed. Eric brought up the idea of incorporating a motion sensor componant, mounted on the bike, so that as the bike slows down, the LEDs start flashing at a different speed or something like that. We still aren't quite sure how we are going to implement the motion sensor (i.e. are we mounting it to the bike? or are we mounting it to the reflector? Here's the code for the arduino, which creates a cool "night rider" effect. Just like David Hasselhoff!

int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int pinArray[] = {2, 3, 4, 5, 6, 7};
int count = 0;
int timer = 30;

void setup(){
// initialize serial communications at 9600 bps:
Serial.begin(9600);
for (count=0;count<6;count++) {
pinMode(pinArray[count], OUTPUT);
}
}

void loop() {
potValue = analogRead(potPin); // read the pot value
// analogWrite(timer); // PWM the LED with the pot value (divided by 4 to fit in a byte)
timer= (potValue/4)+1;
Serial.println(potValue); // print the pot value back to the debugger pane
delay(10); // wait 10 milliseconds before the next loop
for (count=0;count<5;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
for (count=5;count>0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count - 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer*2);
}
}


And here's a video of the LEDs in action:

No comments: