用LED矩阵实现一个字母板,由RPi程序显示不同的字母和符号。
按以下教程安装
https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/
sudo apt-get install git-core sudo apt-get update sudo apt-get upgrade git clone git://git.drogon.net/wiringPi cd wiringPi git pull origin cd wiringPi ./build
|
点阵管脚(我自己定的)
以下是wiringpi库的GPIO号
接线的关系是
GPIO 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
管脚 a b c d e f g h 1 2 3 4 5 6 7 8
#include <wiringPi.h> #include <stdio.h> #include <stdlib.h> int led_digit[10][8]={ 0x00,0x00,0x3E,0x41,0x41,0x3E,0x00,0x00, //0 0x00,0x00,0x21,0x7F,0x01,0x00,0x00,0x00, //1 0x00,0x00,0x23,0x45,0x49,0x31,0x00,0x00, //2 0x00,0x00,0x22,0x49,0x49,0x36,0x00,0x00, //3 0x00,0x00,0x0E,0x32,0x7F,0x02,0x00,0x00, //4 0x00,0x00,0x79,0x49,0x49,0x46,0x00,0x00, //5 0x00,0x00,0x3E,0x49,0x49,0x26,0x00,0x00, //6 0x00,0x00,0x60,0x47,0x48,0x70,0x00,0x00, //7 0x00,0x00,0x36,0x49,0x49,0x36,0x00,0x00, //8 0x00,0x00,0x32,0x49,0x49,0x3E,0x00,0x00 //9 }; int row[8]={7,6,5,4,3,2,1,0}; //abc int lin[8]={8,9,10,11,12,13,14,15}; //123
void shownum(int num){ for(int j=0;j<8;j++){ for(int k=0;k<8;k++) digitalWrite(lin[k],HIGH); digitalWrite(lin[j],LOW); for(int i=0;i<8;i++){ if((led_digit[num][j]>>i)&1){ digitalWrite(row[i],HIGH); // printf ("%d-----%d\n",low,i); } else digitalWrite(row[i],LOW); delay(0); } } }
int main (void) { int number=0 ; int flag=1; printf ("Raspberry Pi program\n") ; if (wiringPiSetup () == -1) exit (1) ; for(int i=0;i<8;i++){ pinMode (row[i], OUTPUT); pinMode (lin[i], OUTPUT); }
/* for(int i=0;i<8;i++){ digitalWrite(lin[i],LOW); for(int j=0;j<8;j++){ digitalWrite(row[j],HIGH); printf("%d,%d\n" , i,j); delay(100); digitalWrite(row[j],LOW);
} digitalWrite(lin[i],HIGH); } */ for(;;){ for(int i=0;i<100;i++) shownum(number%10); number++; } return 0 ; }
|
编译命令
gcc -o 8x8led 8x8led.cpp -lwiringPi |
http://v.youku.com/v_show/id_XNTcyODk4MjQw.html