Wednesday, October 10, 2007

Some code with that project?


Here's the Arduino code that we've been using for the bike reflector project. It's probably going to change a bit between now and the final stages, but here's what we got right now. Oh, and here's a picture of the group doing some on-site bike reflector research at K Mart.


int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int ledPin = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop() {
potValue = analogRead(potPin); // read the pot value
Serial.println(potValue); // print the pot value back to the debugger pane
// wait 10 milliseconds before the next loop
if (potValue<1000) {
//delay(1000);
digitalWrite(ledPin, HIGH);
} else {
// if(potValue<500)
delay(1000);
digitalWrite(ledPin, LOW);

}

}

No comments: