TA的每日心情 | 擦汗 2015-3-6 13:14 |
---|
签到天数: 6 天 连续签到: 1 天 [LV.2]偶尔看看I
|
52pi老邓做了个LCD屏幕,
这个屏幕是给BPI也就是香蕉派制作的,
通过一个叫mcp23017的i2c芯片,
扩展出了16个双向I/O,
一个模块集成了三种功能,
1、一块1602屏幕,蓝屏
2、一个RGB-LED,亮瞎眼,盲打中
3、五个独立按键
#include #include #include #include #include #include int page=3; int select=1; int display; int color=0; pthread_t id; void show() { time_t timep; structtm *ptm; digitalWrite ( 113, LOW); digitalWrite ( 114, LOW); digitalWrite ( 115, LOW); lcdPosition(display,0,0); switch(page) { case 0: if (select==1) { lcdPrintf(display,">>1.Joytag Time "); lcdPrintf(display," 2.Uncle's RGB "); } else { lcdPrintf(display," 1.Joytag Time "); lcdPrintf(display,">>2.Uncle's RGB "); } break; case 1: time(&timep); ptm=localtime(&timep); lcdPrintf(display," d/d/d ",1900+ptm->tm_year, 1+ptm->tm_mon, ptm->tm_mday); lcdPrintf(display," d:d:d ",ptm->tm_hour, ptm->tm_min, ptm->tm_sec); break; case 2: lcdPrintf(display," **Uncle's RGB**"); lcdPrintf(display," Color: %d ",color); digitalWrite ( 113, color&0x01); digitalWrite ( 114, color&0x02); digitalWrite ( 115, color&0x04); color=(color+1)%8; delay(400); break; case 3: lcdPrintf(display,"RGB&1602 Module "); lcdPrintf(display,"For BPI 52pi.net"); break; } delay(100); } void key(void) { int i; while(1) { for(i=108;i<113;i++) { if (digitalRead(i)>0) { switch(i) { case 108: page=0; break; case 109: select=select%2+1; break; case 110: page=3; break; case 111: page=select; break; case 112: select=select%2+1; break; } delay(400); } } delay(100); } } int main() { wiringPiSetup(); mcp23017Setup (100, 0x20); pthread_create(&id,NULL,(void *)key,NULL); digitalWrite(107,1); digitalWrite(101,0); display=lcdInit(2,16,4,100,102,103,104,105,106,0,0,0,0); lcdHome(display); while(1) show(); }
首先是欢迎界面,点击右边单独的按键进入菜单
一共两个选项,没做翻页,
1、卓泰的时间
2、二叔的LED
上下键选择,右键选定,左键可以进入欢迎页面
点击右边单独的键,退回到Menu
千万不要直视,会死人的!
运行办法:
- gcc bpi1602.c -lwiringPi /opt/gpio-lib/WiringBPi_Beta_V2.0/devLib/lcd.o -o bpi1602
- ./bpi1602
二叔科技原创,关注二叔科技 https://2.liub.org
二叔科技.创客空间 167153362 |
|