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