Wednesday, May 18, 2011

Simple 1 bit 7-segment LED counter


/*
counter
created 2011/05/18
Sudip Shrestha
Sulav Timsina
*/
int count=0;
int delay_val=1000;

// The setcountup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);

}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
switch (count) {
case 0:
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
delay(delay_val);

//do something when var equals 1
break;
case 1:
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
delay(delay_val);
//do something when var equals 2
break;
case 2:
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
delay(delay_val);
//do something when var equals 2
break;
case 3:
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
delay(delay_val);
//do something when var equals 2
break;
case 4:
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(delay_val);
//do something when var equals 2
break;
case 5:
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(delay_val);
//do something when var equals 2
break;
case 6:
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(delay_val);
//do something when var equals 2
break;
case 7:
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
delay(delay_val);
//do something when var equals 2
break;
case 8:
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(delay_val);
//do something when var equals 2
break;
case 9:
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(8, LOW);
digitalWrite(7, LOW);
digitalWrite(6, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(delay_val);
//do something when var equals 2
break;
}

if (count > 9)
{
count=0;
//action A
}
else
{
count=count+1;
// action B
}
}

No comments:

Post a Comment