Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * matrixMpxAnimation sketch
- * animates two heart images to show a beating heart
- */
- // the heart images are stored as bitmaps - each bit corresponds to an LED
- // a 0 indicates the LED is off, 1 is on
- byte P[] = {
- B11111111,
- B10000001,
- B10000001,
- B11111111,
- B10000000,
- B10000000,
- B10000000,
- B10000000};
- byte E[] = {
- B11111111,
- B10000000,
- B10000000,
- B10000000,
- B11111111,
- B10000000,
- B10000000,
- B11111111};
- byte M[] = {
- B10000001,
- B11000101,
- B11001001,
- B10010001,
- B10000001,
- B10000001,
- B10000001,
- B10000001};
- byte A[] = {
- B00011000,
- B00100100,
- B01000010,
- B10000001,
- B11111111,
- B10000001,
- B10000001,
- B10000001};
- byte L[] = {
- B10000000,
- B10000000,
- B10000000,
- B10000000,
- B10000000,
- B10000000,
- B10000000,
- B11111111};
- const int columnPins[] = { 2, 3, 4, 5, 6, 7, 8, 9};
- const int rowPins[] = { 10,11,12,15,16,17,18,19};
- void setup() {
- for (int i = 0; i < 8; i++)
- {
- pinMode(rowPins[i], OUTPUT); // make all the LED pins outputs
- pinMode(columnPins[i], OUTPUT);
- digitalWrite(columnPins[i], HIGH); // disconnect column pins from Ground
- }
- }
- void loop() {
- int pulseDelay = 800 ; // milliseconds to wait between beats
- show(P, 160);
- show(A, 160); // followed by the big heart for 200ms
- show(M, 160);
- show(E, 160);
- show(L, 160);
- show(A, 160);
- delay(pulseDelay); // show nothing between beats
- }
- // routine to show a frame of an image stored in the array pointed to by the image parameter.
- // the frame is repeated for the given duration in milliseconds
- void show( byte * image, unsigned long duration)
- {
- unsigned long start = millis(); // begin timing the animation
- while (start + duration > millis()) // loop until the duration period has passed
- {
- for(int row = 0; row < 8; row++)
- {
- digitalWrite(rowPins[row], HIGH); // connect row to +5 volts
- for(int column = 0; column < 8; column++)
- {
- boolean pixel = bitRead(image[row],column);
- if(pixel == 1)
- {
- digitalWrite(columnPins[column], LOW); // connect column to Gnd
- }
- delayMicroseconds(300); // a small delay for each LED
- digitalWrite(columnPins[column], HIGH); // disconnect column from Gnd
- }
- digitalWrite(rowPins[row], LOW); // disconnect LEDs
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement