Friday, December 5, 2014

Code #1

Possible code: -

long period = 400;

int ledPins[6][3] = {{4, 3, 2}, {7, 6, 5}, {10, 9, 8}, {13, 12, 11}, {16, 15, 14}, {19, 18, 17}};

int n = 128;
char *message[6] = {
"44000440011111110022000005500000066666000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"44000440011000000022000005500000660006600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"44444440011111000022000005500000660006600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"44000440011000000022000005500000660006600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"44000440011111110022222005555500066666000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
};

void setup()
{
 for (int led = 0; led < 6; led ++)
 {
   for (int color = 0; color < 3; color++)
   {
     pinMode(ledPins[led][color], OUTPUT);
   }
 }
}

void loop()
{
  for (int col = 0; col < n; col++)
  {
    for (int row = 0; row < 6; row++)
    {
      int color = (int)(message[5-row][col] - '0');
      setLed(row, color); 
    }
    delayMicroseconds(period);
    allOff();
    delayMicroseconds(period / 16);
  }
}

void setLed(int led, int color)
{
 digitalWrite(ledPins[led][0], !(color & 1));
 digitalWrite(ledPins[led][1], !(color & 2));
 digitalWrite(ledPins[led][2], !(color & 4)); 
}

void allOff()
{
   for (int led = 0; led < 6; led ++)
 {
   for (int color = 0; color < 3; color++)
   {
     digitalWrite(ledPins[led][color], HIGH);
   }
 }
}

Source: -
http://www.instructables.com/files/orig/FIB/8DN6/HHS9HC8T/FIB8DN6HHS9HC8T.txt

Priyank

No comments:

Post a Comment