Go Down

Topic: Happy Xmas POV display (Read 655 times) previous topic - next topic

Hi folks

I thought some one might be interested in this simple POV code which spells out Happy Xmas using LEDs on D2 to D10:-


int HappyXmas[50] = {254,16,16,254,0,62,72,72,62,0,63,68,68,56,0,63,68,68,56,0,0,114,9,9,126,0,0,198,40,16,40,198,62,96,62,96,62,0,62,72,72,62,0,36,82,74,36,0,0,0};

void setup() {:
for  (int i=0; i< 20; i++) pinMode(i,OUTPUT);
for  (int i=0; i< 20; i++) digitalWrite(i,LOW);
}

void loop() {
for  (int j=0; j< 50; j++)
    {
    int Row = HappyXmas[j];
    for  (int i=0; i< 8; i++)
      {
      // LEds on D2 to D10.
      if (Row == (Row/2)*2)digitalWrite(i+2,LOW);  else digitalWrite(i+2,HIGH);   
      Row = Row >> 1;
      };
    delay(2);   
    };
   delay(100);
}

tuxduino

There's a : in there that will prevent the code from even compiling.

Too many ;'s around...

Why do you initialize D0 to D19 if you only use D2..D10 ?

Here's a slightly modified version:

Code: [Select]

// LEds on D2 to D10.

#define ARY_LEN(a) (sizeof(a)/(sizeof(a[0])))

int HappyXmas[] = {
    254,16,16,254,0,62,72,72,62,0,63,68,68,56,0,63,68,68,56,0,0,114,9,9,126,0,0,198,40,16,40,198,62,96,62,96,62,0,62,72,72,62,0,36,82,74,36,0,0,0
};


void setup() {
    for  (int i = 0; i < 20; i++) pinMode(i,OUTPUT);
    for  (int i = 0; i < 20; i++) digitalWrite(i,LOW);
}

void loop() {
    for  (int j = 0; j < ARY_LEN(HappyXmas); j++) {
        int Row = HappyXmas[j];
        for (int i = 0; i < 8; i++) {
            if (bitRead(Row, i)) {
                digitalWrite(i+2, HIGH);   
            }
            else {
                digitalWrite(i+2, LOW);
            }
            Row = Row >> 1;
        }
        delay(2);   
    }
    delay(100);
}

tuxduino

Edit: there's an error: D2..D10 are 9 pins, so in fact you're only using D2..D9

Here's a 2nd revision:

Code: [Select]

// LEds on D2 to D9.


#define ARY_LEN(a) (sizeof(a)/(sizeof(a[0])))


byte ledPins[] = {
    2, 3, 4, 5, 6, 7, 8, 9
};

const byte NUM_PINS = ARY_LEN(ledPins);


unsigned int HappyXmas[] = {
    254,16,16,254,0,62,72,72,62,0,63,68,68,56,0,63,68,68,56,0,0,114,9,9,126,0,0,198,40,16,40,198,62,96,62,96,62,0,62,72,72,62,0,36,82,74,36,0,0,0
};

const byte NUM_ROWS = ARY_LEN(HappyXmas);


void setup() {
    for  (int i = 0; i < NUM_PINS; i++) {
        pinMode(i, OUTPUT);
        digitalWrite(i, LOW);
    }
}


void loop() {
    for  (int j = 0; j < NUM_ROWS; j++) {
       
        int Row = HappyXmas[j];
       
        for (int i = 0; i < NUM_PINS; i++) {
            if (bitRead(Row, i)) {
                digitalWrite(ledPins[i], HIGH);   
            }
            else {
                digitalWrite(ledPins[i], LOW);
            }
        }
        delay(2);   
    }
    delay(100);
}


Also, how is it all wired up ? The leds must be moving somehow I guess...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy