基于ARM开发板的智能钢琴的设计
下面展示一些 内联代码片
。
// A code block
var foo = 'bar';
// An highlighted block
main函数:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include "ts.h"
#include "lcd.h"
int x,y,ts_sta,push;
//小钢琴
void piano(void);
//线程获取坐标
void *pthread_get_ts(void * arg)
{
while(1)
ts_sta = get_xy(&x,&y,&push);
}
int main(int argc, const char *argv[])
{
//初始化触摸屏
open_ts();
//初始化LCD
open_lcd();
//创建线程
pthread_t thr;
pthread_create(&thr,NULL,pthread_get_ts,NULL);
while(1)
{
show_bmp("zhu.bmp",0,0);
if(x>10 && x<700){
piano();//小钢琴
}
}
//关闭LCD TS
close_lcd();
close_ts();
}
//小钢琴
void piano(void)
{
int n,last_n;//键值、上次的键值,也就是按下的哪个按键
char buf[64];//拼接用
int vol=0;//音量
int mot=1; //模式,主题
//显示界面
show_bmp("./bmp1/background.bmp",0,0);
show_bmp("./bmp1/bar.bmp",0,0);
show_bmp("./bmp1/logo.bmp",260,400);
show_bmp("./bmp1/jiajian.bmp",670,400);
show_bmp("./bmp1/zhuanhuan.bmp",30,400);
while(1)
{
if(push == 1 && y>55 && y<320)//如果触摸屏按下
{
for(n=0; n<12; n++){
//看一下是按下的哪个按键
if(x>n*66 && x<(n+1)*66 && last_n!=n){
printf("%d [%d %d]\n",ts_sta,x,y);//打印坐标
sprintf(buf,"madplay -A %d ./mp3%d/d%d.mp3 &",vol,mot,n+1);
system("killall -9 madplay");
system(buf);//播放相应音频
sprintf(buf,"./bmp%d/key_on.bmp",mot);
show_bmp(buf,n*66,48);//显示按键按下图片
if(last_n != -1){
sprintf(buf,"./bmp%d/key_off.bmp",mot);
show_bmp(buf,last_n*66,48);//显示松开图片
}
last_n = n;
break;
}
}
}
else if(push == 0)//如果触摸屏松开
{
last_n = -1;
for(n=0; n<12; n++){
//把按键都复原
sprintf(buf,"./bmp%d/key_off.bmp",mot);
show_bmp(buf,n*66,48