Thursday, September 11, 2008

Fixing Physical Computing Homework

Thanks Kevin it seems to work :)

My brother Kevin, who lives in Florida and works as a Flash developer, had an idea about how to fix my code. He sent me a snippet of the void loop() section and I swapped it in and then rearranged the variables.

His idea was to check the switchState on every iteration of the for loop. Since switchState would only return 0 or 1(no or yes), he added the value of switchState to the lower of the two LED pins(pin 3) which were in pins 3 and 4.

Code snippet:
void loop() {
for (int i=10; i >= 1; i--){
// read the switch input at the beginning of
// each loop iteration
switchState = digitalRead(switchPin);
digitalWrite((ledPin + switchState), HIGH);
delay(i*(i*10));
digitalWrite((ledPin + switchState), LOW);
delay(i*(i*10));
}

Here is a video:


Physical Computing Week 1 Homework FIXED from Matt Richard on Vimeo.

1 comment:

  1. Cool! Glad it worked! By the way, the e360mag.net site is about three years old... The site that I am concentrating on is www.e360live.com or you can check out some of the launchpages: www.e360live.com/launchpage, www.e360live.com/rxp, or www.e360live.com/cocacolahiphop to name a few).

    ReplyDelete