/* Filename: 8x8hello.c The file to include the font must be in the working directory, it's filename is: 8x8font.dat Turns on and off LEDs at to display letters in an 8x8 matrix. Pins 0-7 are the row pins, on if HIGH. Pins 8-15 are the column pins, on if LOW. The array for each letter looks like this: int f_A[8][8] = { {0,0,0,0,0,0,0,0}, // Letter "A" {0,0,1,0,0,0,0,0}, {0,1,0,1,0,0,0,0}, {1,0,0,0,1,0,0,0}, {1,1,1,1,1,0,0,0}, {1,0,0,0,1,0,0,0}, {1,0,0,0,1,0,0,0}, {1,0,0,0,1,0,0,0} }; */ #include #include #include #include #include "./8x8font.dat" int rowPin[8] = {0,1,2,3,4,5,6,7}; int columnPin[8] = {8,9,10,11,12,13,14,15}; int LED[8][8]; //8 rows, 8 columns. Used for passing data between threads. void setup(void) { int i; if (geteuid() != 0) { fprintf (stderr, "You need to be root to run this program. (sudo?)\n") ; exit(0) ; } if (wiringPiSetup() == -1) { printf("wiringPiSetup error\n"); exit(1) ; } for(i = 0; i < 16; i++) { pinMode(i,OUTPUT); // Set pins 0 - 15 for output. } } /* This thread reads the LED array and performs the multiplex. It turns on the pins for one LED at a time. Row 1 LED 1 - 2 - 3 ... Row 2 LED 1 - 2 - 3 ... The code here runs concurrently with the main program in an infinite loop. */ PI_THREAD (display) { int i,j; while(1) { for(i = 0; i < 8; i++) // Row, HIGH is on. { if(i==0) digitalWrite(rowPin[7],0); // Turn off previous row. else digitalWrite(rowPin[i-1],0); digitalWrite(columnPin[7],1); // turn off column 7 pin. digitalWrite(rowPin[i],1); // Turn on current row. for(j = 0; j < 8; j++) // Column, LOW is on. { if(j==0) digitalWrite(columnPin[7],1); // Turn off previous column. else digitalWrite(columnPin[j-1],1); if (LED[i][j]==1) { digitalWrite(columnPin[j],0); // Turn on current column. } } } } } /* Function to display one letter. The letter array is copied to the LED array. */ void dspLetter(int letter[8][8]) { int i,j; for(i=0;i<8;i++) { for(j=0;j<8;j++) { LED[i][j] = letter[i][j]; //Move letter to LED for display } } } /* The loop function writes passes the letters to the dspLetter function. */ void loop(void) { dspLetter(f_H); delay(500); dspLetter(f_E); delay(500); dspLetter(f_L); delay(500); dspLetter(f_SP); delay(200); dspLetter(f_L); delay(500); dspLetter(f_O); delay(500); dspLetter(f_SP); delay(1000); dspLetter(f_W); delay(500); dspLetter(f_O); delay(500); dspLetter(f_R); delay(500); dspLetter(f_L); delay(500); dspLetter(f_D); delay(500); dspLetter(f_SP); delay(1000); dspLetter(f_A); delay(500); dspLetter(f_B); delay(500); dspLetter(f_C); delay(500); dspLetter(f_D); delay(500); dspLetter(f_E); delay(500); dspLetter(f_F); delay(500); dspLetter(f_G); delay(500); dspLetter(f_H); delay(500); dspLetter(f_I); delay(500); dspLetter(f_J); delay(500); dspLetter(f_K); delay(500); dspLetter(f_L); delay(500); dspLetter(f_M); delay(500); dspLetter(f_N); delay(500); dspLetter(f_O); delay(500); dspLetter(f_P); delay(500); dspLetter(f_Q); delay(500); dspLetter(f_R); delay(500); dspLetter(f_S); delay(500); dspLetter(f_T); delay(500); dspLetter(f_U); delay(500); dspLetter(f_V); delay(500); dspLetter(f_W); delay(500); dspLetter(f_X); delay(500); dspLetter(f_Y); delay(500); dspLetter(f_Z); delay(500); dspLetter(f_SP); delay(1000); } int main(void) { int x = piThreadCreate (display) ; // Start second thread. if (x != 0) printf ("It didn't start.\n"); setup(); while(1) { loop(); } return(0); }