K2000 Example

From Pinguino
Jump to: navigation, search


Example for functions: pinMode digitalWrite delay

/**
*	K2000 - Display a light moving from one side to the other.
*	Jean-Pierre Mandon 2008
*	Sebastien Koechlin 2009
*	
*	Hardware:  8 LED connected to ground with appropriate resistors on pin 0 to 7
*/

// Wait duration in ms
#define SMALL 35
#define LONG 100

int i;				// Iterator

void setup(void)
{
        for (i=0;i<8;i++)
        {
                pinMode(i,OUTPUT);	// pin 0 to 7 as OUTPUT
                digitalWrite(i,LOW);	// pin 0 to 7 at LOW level
        }
	digitalWrite(0,HIGH);		// pin 0 at HIGH level (LED 0 lighted)
}


void loop(void)
{
	// LED state: 1-0-0-0-0-0-0
        for (i=1;i<8;i++)       	// For LED 1 to LED 7
        {
                digitalWrite(i,HIGH);	// Switch on current LED
		delay(SMALL);
		digitalWrite(i-1,LOW);	// Switch off previous LED
                delay(LONG);
        }
	
	// LED state: 0-0-0-0-0-0-0-1
	for (i=6;i>=0;i--)        	// For LED 6 to LED 0
        {
                digitalWrite(i,HIGH);	
		delay(SMALL);
		digitalWrite(i+1,LOW);
                delay(LONG);
        }
}
Here is the result:
Picture of a Test-Board running K2000