Tutorial.KnightRider History

Hide minor edits - Show changes to output

September 07, 2006, at 02:57 AM by Clay Shirky - Knihgt typo fix
Changed lines 1-2 from:
!!Knigth Rider
to:
!!Knight Rider
Changed line 145 from:
* This example concentrates in making the visuals fluid.
to:
* This example concentrates on making the visuals fluid.
January 04, 2006, at 10:13 AM by 193.222.246.29 -
Deleted line 160:
pinMode(ledPin, OUTPUT);
November 11, 2005, at 09:07 AM by 81.236.128.105 -
Changed lines 7-8 from:
This example makes use of 6 LEDs connected to the pins 2 - 7 on the board. The first code example will make the LEDs blink in a sequence, one by one using only '''digitalWrite(pinNum,HIGH/LOW)''' and '''delay(time)'''. The second example shows how to use a '''for(;;)''' construction to perform the very same thing, but in fewer lines. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way.
to:
This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The first code example will make the LEDs blink in a sequence, one by one using only '''digitalWrite(pinNum,HIGH/LOW)''' and '''delay(time)'''. The second example shows how to use a '''for(;;)''' construction to perform the very same thing, but in fewer lines. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way.
November 11, 2005, at 09:06 AM by 81.236.128.105 -
Added lines 1-182:
!!Knigth Rider

We have named this example in memory to a TV-series from the 80's where the famous David Hasselhoff had an AI machine driving his Pontiac. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects.

Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board, it would be interesting to use the '''Knight Rider''' as a metaphor.

This example makes use of 6 LEDs connected to the pins 2 - 7 on the board. The first code example will make the LEDs blink in a sequence, one by one using only '''digitalWrite(pinNum,HIGH/LOW)''' and '''delay(time)'''. The second example shows how to use a '''for(;;)''' construction to perform the very same thing, but in fewer lines. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way.

[[http://static.flickr.com/27/61933851_3b9a25ab42_o.jpg|http://static.flickr.com/27/61933851_3b9a25ab42.jpg]]

''Example for Hasselhoff's fans''


!!!Knight Rider 1

[=
/* Knight Rider 1
* --------------
*
* Basically an extension of Blink_LED.
*
*
* (cleft) 2005 K3, Malmo University
* @author: David Cuartielles
* @hardware: David Cuartielles, Aaron Hallborg
*/

int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int timer = 100;

void setup(){
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
pinMode(pin6, OUTPUT);
pinMode(pin7, OUTPUT);
}

void loop() {
digitalWrite(pin2, HIGH);
delay(timer);
digitalWrite(pin2, LOW);
delay(timer);

digitalWrite(pin3, HIGH);
delay(timer);
digitalWrite(pin3, LOW);
delay(timer);

digitalWrite(pin4, HIGH);
delay(timer);
digitalWrite(pin4, LOW);
delay(timer);

digitalWrite(pin5, HIGH);
delay(timer);
digitalWrite(pin5, LOW);
delay(timer);

digitalWrite(pin6, HIGH);
delay(timer);
digitalWrite(pin6, LOW);
delay(timer);

digitalWrite(pin7, HIGH);
delay(timer);
digitalWrite(pin7, LOW);
delay(timer);

digitalWrite(pin6, HIGH);
delay(timer);
digitalWrite(pin6, LOW);
delay(timer);

digitalWrite(pin5, HIGH);
delay(timer);
digitalWrite(pin5, LOW);
delay(timer);

digitalWrite(pin4, HIGH);
delay(timer);
digitalWrite(pin4, LOW);
delay(timer);

digitalWrite(pin3, HIGH);
delay(timer);
digitalWrite(pin3, LOW);
delay(timer);
}
=]

!!!Knight Rider 2

[=
/* Knight Rider 2
* --------------
*
* Reducing the amount of code using for(;;).
*
*
* (cleft) 2005 K3, Malmo University
* @author: David Cuartielles
* @hardware: David Cuartielles, Aaron Hallborg
*/

int pinArray[] = {2, 3, 4, 5, 6, 7};
int count = 0;
int timer = 100;

void setup(){
// we make all the declarations at once
for (count=0;count<6;count++) {
pinMode(pinArray[count], OUTPUT);
}
}

void loop() {
for (count=0;count<6;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer);
}
for (count=5;count>=0;count--) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer);
}
}
=]

!!!Knight Rider 3

[=
/* Knight Rider 3
* --------------
*
* This example concentrates in making the visuals fluid.
*
*
* (cleft) 2005 K3, Malmo University
* @author: David Cuartielles
* @hardware: David Cuartielles, Aaron Hallborg
*/

int pinArray[] = {2, 3, 4, 5, 6, 7};
int count = 0;
int timer = 30;

void setup(){
for (count=0;count<6;count++) {
pinMode(pinArray[count], OUTPUT);
}
pinMode(ledPin, OUTPUT);
}

void 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);
}
}
=]

Share