標題: 基于ARM平臺的鋼琴游戲 實現(xiàn)琴鍵按下效果 [打印本頁]

作者: why684700    時間: 2017-7-25 15:29
標題: 基于ARM平臺的鋼琴游戲 實現(xiàn)琴鍵按下效果
效果文件都在文件里,可以下載看看。很全,有興趣就了解下。。

本階段任務與步驟
================
1,設置好共享文件夾

2,編譯這些代碼:
   make

3,將編譯好的示例程序piano丟到開發(fā)板,觀察運行效果
   注意:要將所有的bmp文件也要上傳到開發(fā)板(已經(jīng)上傳過了就不用重復上傳了)

4,修改piano.c,使得鋼琴12個琴鍵均能按下去。


單片機源程序如下:
  1. /***********************************************
  2. //
  3. //  Copyright(C), 2013-2016, GEC Tech. Co., Ltd.
  4. //
  5. //  作者: 林世霖
  6. //  微信公眾號:秘籍酷
  7. //  日期: 2016-6
  8. //
  9. //  描述: 在LCD上顯示音樂鋼琴的界面
  10. //
  11. //  GitHub: github.com/vincent040
  12. //  Bug Report: 2437231462@qq.com
  13. //
  14. ***********************************************/

  15. #include <stdio.h>
  16. #include <signal.h>
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <syslog.h>
  21. #include <errno.h>
  22. #include <linux/input.h>

  23. #include <fcntl.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/mman.h>
  27. #include <stdbool.h>

  28. #include <linux/fb.h>
  29. #include <sys/mman.h>
  30. #include <sys/ioctl.h>

  31. #include "bmp.h"
  32. #include "ts.h"

  33. int main(int argc, char const *argv[])
  34. {
  35.         // 1,打開LCD設備
  36.         int lcd = open("/dev/fb0", O_RDWR);

  37.         // 2,獲取LCD設備的參數(shù)
  38.         struct fb_var_screeninfo vinfo;
  39.         ioctl(lcd, FBIOGET_VSCREENINFO, &vinfo);

  40.         // 3,為該LCD設備映射顯存
  41.         unsigned char *FB;
  42.         FB = mmap(NULL, vinfo.xres * vinfo.yres * vinfo.bits_per_pixel/8,
  43.                                         PROT_READ|PROT_WRITE, MAP_SHARED, lcd, 0);

  44.         // 4,顯示整個鋼琴的界面
  45.         //    4.1 顯示背景(background.bmp)
  46.         bmp2lcd("background.bmp", FB, &vinfo, 0, 0);

  47.         //    4.2 顯示標題欄(bar.bmp)
  48.         bmp2lcd("bar.bmp", FB, &vinfo, 0, 0);

  49.         //    4.3 顯示12個琴鍵(bar.bmp)
  50.         int i;
  51.         for(i=0; i<12; i++)
  52.         {
  53.                 bmp2lcd("key_off.bmp", FB, &vinfo, 10+65*i, 47);
  54.         }

  55.         //    4.4 顯示LOGO(logo.bmp)
  56.         bmp2lcd("logo.bmp", FB, &vinfo, 214, 355);


  57.         // 5,打開觸摸屏設備,開始音樂鋼琴
  58.         int ts = open("/dev/event0", O_RDWR);
  59.         struct coordinate coor;

  60.         while(1)
  61.         {
  62.                 // 5.1 等待手指觸碰,并順便獲取觸碰點坐標(coor.x和coor.y)
  63.                 wait4touch(ts, &coor);

  64.                 // 5.2 根據(jù)coor的坐標信息來更新琴鍵的狀態(tài)
  65.                 bmp2lcd("key_on.bmp", FB, &vinfo,(coor.x-10)/65*65+10, 47);

  66.                 // 5.3 根據(jù)coor的坐標信息播放相應的琴鍵聲音(暫時不做)
  67.                

  68.                 // 5.4 等待手指的松開
  69.                 wait4leave(ts);

  70.                 // 5.5 將相應的琴鍵恢復彈起的狀態(tài)
  71.                 bmp2lcd("key_off.bmp", FB, &vinfo,(coor.x-10)/65*65+10,  47);
  72.         }
  73.        
  74.         return 0;
  75. }







  76.         // int ts = open("/dev/event0", O_RDWR);
  77.         // struct coordinate coor;

  78.         // while(1)
  79.         // {
  80.         //         // 5.1 等待手指觸碰,并順便獲取觸碰點坐標(coor.x和coor.y)
  81. ……………………

  82. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
06實現(xiàn)琴鍵按下效果.rar (10.25 KB, 下載次數(shù): 38)



作者: zzjay    時間: 2019-7-4 13:00
最好把仿真文件,程序文件都上傳,文檔中寫的都不全





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1