LOL - I thought i'd write one from scratch using no help at all just to test myself and how well i'm getting used to C.
//written by Craig Capel, free to use, this is using an 8 Segment LED digit thingy
//I simply have pins 2 through to pin 9
//pin 2, pin1 (bottom left of the LED Segment)
//pin 3, pin2 .... and so on. when you get to the last pin at the bottom of the LED segment
//pin 6 goes top left of the LED segment, pin 7, next to it...
byte v0[] = {2,3,4,7,9,8,0}; //0 Value
byte v1[] = {9,4,0}; //1 etc....
byte v2[] = {8,9,5,2,3,0};
byte v3[] = {8,9,5,4,3,0};
byte v4[] = {7,9,5,4,0};
byte v5[] = {8,7,5,4,3,0};
byte v6[] = {7,2,3,4,5,0};
byte v7[] = {8,9,4,0};
byte v8[] = {2,3,4,5,7,8,9,0};
byte v9[] = {4,9,8,7,5,0};
//byte v2[] = {8,9,5,2,3};
//byte v3[] = {2,3,4,5,6,7,8,9};
byte LEDValue = 0;
void setup()
{
int n;
Serial.begin(9600);
for(n=2; n<=9; n++)
{
pinMode(n,OUTPUT);
digitalWrite(n,HIGH);
// Serial.println(n);
// delay(4000);
// digitalWrite(n,LOW);
}
}
void loop()
{
// PatternSeq1();
// for(int n=2; n<=9; n++)
// digitalWrite(n,HIGH);
// delay(2000);
if(LEDValue==10) LEDValue=0;
Serial.print(LEDValue);
Serial.print(":");
// Serial.println(
Display(LEDValue);
delay(500);
LEDValue++;
}
int terminator(byte req[])
{
int n = 0;
int v = 0;
do
{
v = req[n];
// Serial.print("array index: ");
// Serial.print(n);
// Serial.println();
// Serial.print("Value: ");
// Serial.println(v); //does not stop when it hits 0 in the array?!
// delay(100);
// Serial.println("!!!!");
n++;
} while(v!=0);
// Serial.print("return elements: ");
// Serial.println(n-1);
// delay(2000);
return n-1;
}
void Display(byte Val)
{
int items,V,n = 0;
Clear();
if (Val==0) { items=terminator(v0); for(n=0; n<items; n++) digitalWrite(v0[n],HIGH); }
if (Val==1) { items=terminator(v1); for(n=0; n<items; n++) digitalWrite(v1[n],HIGH); }
if (Val==2) { items=terminator(v2); for(n=0; n<items; n++) digitalWrite(v2[n],HIGH); }
if (Val==3) { items=terminator(v3); for(n=0; n<items; n++) digitalWrite(v3[n],HIGH); }
if (Val==4) { items=terminator(v4); for(n=0; n<items; n++) digitalWrite(v4[n],HIGH); }
if (Val==5) { items=terminator(v5); for(n=0; n<items; n++) digitalWrite(v5[n],HIGH); }
if (Val==6) { items=terminator(v6); for(n=0; n<items; n++) digitalWrite(v6[n],HIGH); }
if (Val==7) { items=terminator(v7); for(n=0; n<items; n++) digitalWrite(v7[n],HIGH); }
if (Val==8) { items=terminator(v8); for(n=0; n<items; n++) digitalWrite(v8[n],HIGH); }
if (Val==9) { items=terminator(v9); for(n=0; n<items; n++) digitalWrite(v9[n],HIGH); }
// delay(5000);
}
void Clear()
{
int n;
for(n=2; n<=9;)
{
digitalWrite(n,LOW);
// delay(90);
n++;
}
}
void PatternSeq1()
{
int n;
for(n=2; n<=9; n++)
{
digitalWrite(n,HIGH);
delay(500);
}
for(n=9; n>=2; n--)
{
digitalWrite(n,LOW);
delay(500);
}
}
once compiled, it counts from 0 - 9 and outputs it using pins 2-9 (giving a sequence from 0..9)
OK so it works, but now what lol, i have a way of producing a number, 10?..9?...?8 last 10 seconds before new year?... bit of fun
also, posting my code here is a good way of keeping a backup