1 /* Arduino Projects for Dummies
4 * Chapter 6: Making a Scrolling Sign
5 * Creates sprites and text messages using an
6 * 8x8 LED matrix display
8 * This sketch draws a smiley face on the display
9 * and swaps it out with a frowny face
12 * Adapted from Oomlout.com http://www.tinyurl.com/yhwxv6h
15 // Arduino Pin Definitions
16 int rowPin[] = {2,3,4,5,6,7,8,9}; // An Array defining which Arduino pin each row is attached to
17 // (The rows are common anode (driven HIGH))
18 int colPin[] = {17,16,15,14,13,12,11,10}; // An Array defining which pin each column is attached to
19 // (The columns are common cathode (driven LOW))
20 byte smile[] = { // The array used to hold a bitmap of the display
30 byte frown[] = { //The array used to hold a bitmap of the display
42 for(int i = 0; i <8; i++){ // Set the 16 pins used to control the array to be OUTPUTs
43 pinMode(rowPin[i], OUTPUT); // These correspond to the Arduino pins stored in the arrays
44 pinMode(colPin[i], OUTPUT);
50 displaySprite(smile, 1000); // Display the Sprite
51 displaySprite(frown, 1000); // Display the Sprite
54 void displaySprite(byte * data, unsigned long duration){
55 unsigned long start = millis();
56 while (start+duration>millis()){
57 for(int count = 0; count < 8; count++){ // A utility counter
58 for(int i = 0; i < 8; i++){
59 digitalWrite(rowPin[i], LOW); // Turn off all row pins
61 for(int i = 0; i < 8; i++){ // Activate only the Arduino pin of the column to light up
63 digitalWrite(colPin[i], LOW); // Setting this LOW connects the current column's cathode to ground
66 digitalWrite(colPin[i], HIGH); // Setting HIGH Turns all the other rows off
69 for(int row = 0; row < 8; row++){ // Iterate through each pixel in the current column
70 int bit = (data[count] >> row) & 1; // Use a bit shift in the data[] array to do a bitwise comparison
71 // And assign the result of the comparison to the bit
72 if(bit == 1){ // If the bitwise comparison is 1,
73 digitalWrite(rowPin[row], HIGH); // Then light up the LED