25浏览
查看: 25|回复: 2

[项目] 【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目

[复制链接]
概述
主屏幕上有一个大时钟、日期和温度信息,以及音乐播放器和闹钟两个按钮。

Arduino触摸屏音乐播放器主屏幕
进入音乐播放器后,点击屏幕中间的大“播放”按钮即可开始播放音乐。旁边还有两个按钮,分别用于播放上一首或下一首歌曲。

Arduino触摸屏音乐播放器屏幕
这些按钮上方是歌曲进度条,屏幕底部有一个音量条和两个用于降低和增加音量的按钮。右上角有一个时钟,左侧是“菜单”按钮,可返回主屏幕。

另一方面,如果我们进入闹钟,我们可以使用两个按钮来设置小时和分钟来设置闹钟。

Arduino触摸屏闹钟屏幕
当闹钟响起时,一首歌曲将以更高的音量开始播放,并一直播放直到我们按下“关闭”按钮。

Arduino触摸屏闹钟激活
工作原理
现在让我们来看看这款设备的工作原理。它使用一块 Arduino Mega 开发板和一个 3.2 英寸 TFT 触摸屏,并配有合适的屏蔽罩,用于将屏幕连接到 Arduino 开发板。音乐播放使用 BY8001 MP3 播放器模块,闹钟使用 DS3231 实时时钟模块。

Arduino 音乐播放器和闹钟零件清单.jpg
您可以从以下链接获取此 Arduino 项目所需的组件:

BY8001-16P MP3 模块………亚马逊/全球速卖通
3.2 英寸 TFT 触摸显示屏……….…  Amazon  / Banggood / AliExpress
TFT 显示屏超级屏蔽………亚马逊 / Banggood / AliExpress
0.5W 扬声器 ……………………… Amazon  / Banggood / AliExpress
DS3231 实时时钟…… Amazon  / Banggood / AliExpress
Arduino Mega…………………………亚马逊/ Banggood / AliExpress
披露:这些是附属链接。作为亚马逊合作伙伴,我通过符合条件的购买赚取收益。

电路原理图
这是该项目的电路原理图:

Arduino 音乐播放器和闹钟零件清单电路原理图
我们可以在这里注意到,TFT 屏蔽阻挡了 Arduino 板的空闲引脚,因此我们需要制作一个定制的引脚接头,以便能够将它们插入屏蔽和 Arduino 之间。

Arduino 和 TFT 屏幕的定制引脚头
还要注意,为了给 Arduino 供电,我们需要将额外的针头焊接到屏蔽上的 5 V 针脚,因为屏蔽已经使用了所有 Arduino VCC 针脚。

将所有东西连接好后,我们就可以开始对 Arduino 进行编程了。不过,在继续之前,我建议您先看看我之前关于TFT 触摸屏和DS3231 实时时钟模块的详细教程。至于 MP3 播放器模块,我会在本文中简单讲解一下。

BY8001-16P MP3播放器模块
BY8001-16P 是一款 MP3 模块,支持 MicroSD 卡播放,支持 MP3 和 WAV 音频格式。模块内置 3W 功放,可直接驱动单个 3W 扬声器。

BY8100-16P MP3播放器模块
MP3 播放器模块可以使用 5 个输入引脚进行按钮控制,也可以通过串行通信使用微控制器进行控制。

BY8100-16P MP3播放器模块单片机控制
请注意,模块的串口引脚工作电压为 3.3V,因此模块的 RX 引脚需要通过一个 1K 电阻连接到 Arduino 的 TX 引脚。另请注意,A、B 和 C 三个端口用于选择控制模式。如需使用微控制器控制模块,则需要移除这三个引脚上的电阻。引脚 6 和 7 可用于直接连接低功率扬声器,如果使用外部放大器,则可使用引脚 4 和 5。

至于 Arduino 部分,最简单的方法是使用BY8001 库,该库可从 GitHub 下载。打开一些演示示例,就能了解它的工作原理。因此,在设置部分初始化模块后,我们可以使用任何自定义函数来控制模块。

构建设备
我使用 Solidworks 进行了设计,它的外观如下。

Arduino触摸屏音乐播放器和闹钟外壳Solidworks模型
您可以下载此模型,以便在此处进行测量:

对于这个项目,我选择使用铝板,并用多功能工具将其切割成合适的尺寸。然后在桌子边缘,借助一些夹具和板条,我将铝板弯曲。

无需压力机即可折弯金属板
至于扬声器,我打印了一个圆形图案,将其固定到位,然后使用钻头钻出所有孔。

标记侧面
之后,我将侧面切割成适当的形状,并使用胶枪将它们固定到之前弯曲的金属板上。

最后,我给金属板盒子涂了漆,准备安装电子元件了。同样,我用胶枪把所有元件固定好,然后把所有部件连接在一起,最后用两个螺栓固定了设备的后盖。

将电子元件安装到外壳上
就这样,欢迎在下面的评论部分提出任何问题。

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图1

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图2

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图3

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图4

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图5

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图6

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图7

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图8

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图9

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目图10

驴友花雕  中级技神
 楼主|

发表于 7 小时前

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目

项目代码

  1. /*
  2. * Arduino Touch Screen MP3 Music Player and Alarm Clock
  3. *
  4. * Crated by Dejan Nedelkovski,
  5. * www.HowToMechatronics.com
  6. *
  7. * UFTF, URTouch and DS3231 libraries made by Henning Karlsen which can be found and downloaded from his website, www.rinkydinkelectronics.com.
  8. * BY8001 MP3 Player Library made by borland of Arduino forum, Released in public domain. Dowload link: https://github.com/r0ndL/BY8001
  9. */
  10. #include <UTFT.h>
  11. #include <URTouch.h>
  12. #include <SoftwareSerial.h>
  13. #include <BY8001.h>
  14. #include <DS3231.h>
  15. //==== Creating Objects
  16. UTFT     myGLCD(SSD1289, 38, 39, 40, 41); //Parameters should be adjusted to your Display/Schield model
  17. URTouch  myTouch( 6, 5, 4, 3, 2);
  18. SoftwareSerial mp3Serial(11, 10);  // RX, TX
  19. BY8001 mp3;  // creating an instance of class BY8001 and call it 'mp3'
  20. DS3231  rtc(SDA, SCL);
  21. //==== Defining Fonts
  22. extern uint8_t SmallFont[];
  23. extern uint8_t BigFont[];
  24. extern uint8_t SevenSegNumFont[];
  25. extern unsigned int MusicPlayerButton[0x1040];
  26. extern unsigned int AlarmButton[0x1040];
  27. extern unsigned int ButtonPlay[0x1AE9];
  28. extern unsigned int ButtonPause[0x1AE9];
  29. extern unsigned int PreviousButton[0x9C4];
  30. extern unsigned int NextButton[0x9C4];
  31. extern unsigned int VolumeDown[0x170];
  32. extern unsigned int VolumeUp[0x3B8];
  33. int x, y; // Variables for the coordinates where the display has been pressed
  34. char currentPage, playStatus;
  35. int iV = 15;
  36. int trackNum = 1;
  37. int b = 16;
  38. int aHours = 0;
  39. int aMinutes = 0;
  40. boolean alarmNotSet = true;
  41. String alarmString = "";
  42. float currentTemperature, temperature;
  43. static word totalTime, elapsedTime, playback, minutes, seconds, lastSeconds, minutesR, secondsR;
  44. String currentClock, currentHours, currentMinutes, currentSeconds, currentDate;
  45. String timeString, hoursString, minutesString, secondsString, hoursS, minutesS, secondsS, dateS;
  46. void setup() {
  47.   // Initiate display
  48.   myGLCD.InitLCD();
  49.   myGLCD.clrScr();
  50.   myTouch.InitTouch();
  51.   myTouch.setPrecision(PREC_MEDIUM);
  52.   // Initialize the rtc object
  53.   rtc.begin();
  54.   // Music
  55.   Serial.begin(9600);  // set serial monitor baud rate to Arduino IDE
  56.   mp3Serial.begin(9600);  // BY8001 set to 9600 baud (required)
  57.   mp3.setup(mp3Serial); // tell BY8001 library which serial port to use.
  58.   delay(800);  // allow time for BY8001 cold boot; may adjust depending on flash storage size
  59.   
  60.   drawHomeScreen();  // Draws the Home Screen
  61.   currentPage = '0'; // Indicates that we are at Home Screen
  62.   playStatus = '0';
  63.   mp3.setVolume(15);
  64.   delay(100);
  65.   currentTemperature = rtc.getTemp();
  66.   currentDate = rtc.getDateStr();
  67.   currentClock = rtc.getTimeStr();
  68.   timeString = rtc.getTimeStr();
  69.   currentHours = timeString.substring(0, 2);
  70.   currentMinutes = timeString.substring(3, 5);
  71.   currentSeconds = timeString.substring(6, 8);
  72. }
  73. void loop() {
  74.   // Homes Screen
  75.   if (currentPage == '0') {
  76.     // Checks for change of the clock
  77.     if ( currentClock != rtc.getTimeStr()) {
  78.       timeString = rtc.getTimeStr();
  79.       hoursS = timeString.substring(0, 2);
  80.       minutesS = timeString.substring(3, 5);
  81.       secondsS = timeString.substring(6, 8);
  82.       myGLCD.setFont(SevenSegNumFont);
  83.       myGLCD.setColor(0, 255, 0);
  84.       myGLCD.print(secondsS, 224, 50);
  85.       
  86.       if ( currentMinutes != minutesS ) {
  87.         myGLCD.print(minutesS, 128, 50);
  88.         currentMinutes = minutesS;
  89.       }
  90.       if ( currentHours != hoursS ) {
  91.         myGLCD.print(hoursS, 32, 50);
  92.         currentHours = hoursS;
  93.       }
  94.       // Checks for change of the date
  95.       dateS = rtc.getDateStr();
  96.       delay(10);
  97.       if ( currentDate != dateS){
  98.           myGLCD.setColor(255, 255, 255); // Sets color to white
  99.           myGLCD.setFont(BigFont); // Sets font to big
  100.           myGLCD.print(rtc.getDateStr(), 153, 7);
  101.         }
  102.       // Checks for change of the temperature
  103.       temperature = rtc.getTemp();
  104.       delay(10);
  105.       if ( currentTemperature != temperature ){
  106.         myGLCD.setColor(255, 255, 255); // Sets color to white
  107.         myGLCD.setFont(BigFont); // Sets font to big
  108.         myGLCD.printNumI(temperature, 39, 7);
  109.         currentTemperature = temperature;
  110.       }
  111.       delay(10);
  112.       currentClock = rtc.getTimeStr();
  113.     }
  114.     // Checks whether the screen has been touched
  115.     if (myTouch.dataAvailable()) {
  116.       myTouch.read();
  117.       x = myTouch.getX(); // X coordinate where the screen has been pressed
  118.       y = myTouch.getY(); // Y coordinates where the screen has been pressed
  119.       // If we press the Music Player Button
  120.       if ((x >= 55) && (x <= 120) && (y >= 125) && (y <= 190)) {
  121.           drawFrame(87, 157, 33);
  122.           currentPage = '1';
  123.           myGLCD.clrScr();
  124.           delay(100);
  125.           drawMusicPlayerScreen();
  126.           delay(100);
  127.         }
  128.       // If we press the Alarm Button
  129.       if ((x >= 195) && (x <= 260) && (y >= 125) && (y <= 190)) {
  130.           drawFrame(227, 160, 29);
  131.           currentPage = '2';
  132.           myGLCD.clrScr();
  133.         }
  134.     }
  135.   }
  136.   
  137.   // Music Player Screen
  138.   if (currentPage == '1') {
  139.     if (myTouch.dataAvailable()) {
  140.       myTouch.read();
  141.       x = myTouch.getX(); // X coordinate where the screen has been pressed
  142.       y = myTouch.getY(); // Y coordinates where the screen has been pressed
  143.       // If we press the Play Button
  144.       if ((x >= 116) && (x <= 204) && (y >= 77) && (y <= 165)) {
  145.         if (playStatus == '0') {
  146.           drawFrame(159, 121, 42);
  147.           drawPauseButton();
  148.           mp3.playTrackFromFolder(00, 001);
  149.           delay(100);
  150.           playStatus = '2';
  151.           return;
  152.         }
  153.         if (playStatus == '1') {
  154.           drawFrame(159, 121, 42);
  155.           drawPauseButton();
  156.           mp3.play();
  157.           delay(100);
  158.           playStatus = '2';
  159.           return;
  160.         }
  161.         if (playStatus == '2') {
  162.           drawFrame(159, 121, 42);
  163.           drawPlayButton();
  164.           mp3.pause();
  165.           delay(100);
  166.           playStatus = '1';
  167.           return;
  168.         }
  169.       }
  170.       // If we press the Previous Button
  171.       if ((x >= 45) && (x <= 95) && (y >= 97) && (y <= 147)) {
  172.         drawFrame(70, 121, 26);
  173.         mp3.previousTrack();
  174.         delay(100);
  175.         drawTrackBar();
  176.       }
  177.       // If we press the Next Button
  178.       if ((x >= 227) && (x <= 277) && (y >= 97) && (y <= 147)) {
  179.         drawFrame(252, 122, 26);
  180.         mp3.nextTrack();
  181.         delay(100);
  182.         drawTrackBar();
  183.       }
  184.       // If we press the VolumeDown Button
  185.       if ((x >= 35) && (x <= 75) && (y >= 165) && (y <= 209)) {
  186.         drawUnderline(45, 205, 65, 205);
  187.         if (iV >= 0 & iV <= 30) {
  188.           iV--;
  189.           drawVolume(iV);
  190.         }
  191.         mp3.decreaseVolume();
  192.         delay(100);
  193.       }
  194.       // If we press the VolumeUp Button
  195.       if ((x >= 230) && (x <= 280) && (y >= 165) && (y <= 209)) {
  196.         drawUnderline(235, 205, 275, 205);
  197.         if (iV >= 0 & iV <= 30) {
  198.           iV++;
  199.           drawVolume(iV);
  200.         }
  201.         mp3.increaseVolume();
  202.         delay(100);
  203.       }
  204.       // If we press the MENU Button
  205.       if ((x >= 0) && (x <= 75) && (y >= 0) && (y <= 30)) {
  206.         myGLCD.clrScr();
  207.         drawHomeScreen();  // Draws the Home Screen
  208.         currentPage = '0';
  209.         return;
  210.       }
  211.     }
  212.     // Updates the track bar
  213.     if (playStatus == '1' || playStatus == '2') {
  214.       trackPlayTime();
  215.     }
  216.     // Printing the clock in the upper right corner
  217.     myGLCD.setFont(BigFont);
  218.     myGLCD.setColor(255, 255, 255);
  219.     printClock(187, 5);
  220.   }
  221.   // Alarm Clock Screen
  222.   if (currentPage == '2') {
  223.     myGLCD.setFont(BigFont);
  224.     myGLCD.setColor(255, 255, 255);
  225.     myGLCD.print("MENU", 5, 5);
  226.     myGLCD.print("Set Alarm", CENTER, 20);
  227.    
  228.     // Draws a colon between the hours and the minutes
  229.     myGLCD.setColor(0, 255, 0);
  230.     myGLCD.fillCircle (112, 65, 4);
  231.     myGLCD.setColor(0, 255, 0);
  232.     myGLCD.fillCircle (112, 85, 4);
  233.     myGLCD.setFont(SevenSegNumFont);
  234.     myGLCD.setColor(0, 255, 0);
  235.     myGLCD.printNumI(aHours, 32, 50, 2, '0');
  236.     myGLCD.printNumI(aMinutes, 128, 50, 2, '0');
  237.     myGLCD.setColor(255, 255, 255);
  238.     myGLCD.drawRoundRect (42, 115, 82, 145);
  239.     myGLCD.drawRoundRect (138, 115, 178, 145);
  240.     myGLCD.setFont(BigFont);   
  241.     myGLCD.print("H", 54, 122);
  242.     myGLCD.print("M", 150, 122);
  243.    
  244.     myGLCD.drawRoundRect (215, 60, 303, 90);
  245.     myGLCD.print("SET", 236, 67);
  246.     myGLCD.drawRoundRect (215, 115, 303, 145);
  247.     myGLCD.print("CLEAR", 220, 122);
  248.    
  249.     alarmNotSet = true;
  250.         
  251.     while (alarmNotSet){
  252.       if (myTouch.dataAvailable()) {
  253.         myTouch.read();
  254.         x = myTouch.getX(); // X coordinate where the screen has been pressed
  255.         y = myTouch.getY(); // Y coordinates where the screen has been pressed
  256.         //Set hours button
  257.         if ((x >= 42) && (x <= 82) && (y >= 115) && (y <= 145)) {
  258.           drawRectFrame(42, 115, 82, 145);
  259.           aHours++;
  260.           if(aHours >=24){
  261.             aHours = 0;
  262.           }
  263.           myGLCD.setFont(SevenSegNumFont);
  264.           myGLCD.setColor(0, 255, 0);
  265.           myGLCD.printNumI(aHours, 32, 50, 2, '0');
  266.         }
  267.         // Set minutes buttons
  268.         if ((x >= 138) && (x <= 178) && (y >= 115) && (y <= 145)) {
  269.           drawRectFrame(138, 115, 178, 145);
  270.           aMinutes++;
  271.           if(aMinutes >=60){
  272.             aMinutes = 0;
  273.           }
  274.           myGLCD.setFont(SevenSegNumFont);
  275.           myGLCD.setColor(0, 255, 0);
  276.           myGLCD.printNumI(aMinutes, 128, 50, 2, '0');
  277.       }
  278.       // Set alarm button
  279.       if ((x >= 215) && (x <= 303) && (y >= 60) && (y <= 80)) {
  280.         drawRectFrame(215, 60, 303, 90);
  281.         if (aHours < 10 && aMinutes < 10){
  282.           alarmString = "0"+(String)aHours + ":" + "0"+ (String)aMinutes + ":" + "00";
  283.         }
  284.         else if (aHours < 10 && aMinutes > 9){
  285.           alarmString = "0"+(String)aHours + ":" + (String)aMinutes + ":" + "00";
  286.         }
  287.         else if (aHours > 9 && aMinutes < 10){
  288.           alarmString = (String)aHours + ":" + "0"+ (String)aMinutes + ":" + "00";
  289.         }
  290.         else {
  291.           alarmString = (String)aHours + ":" + (String)aMinutes + ":" + "00";
  292.         }
  293.         myGLCD.setFont(BigFont);
  294.         myGLCD.print("Alarm set for:", CENTER, 165);
  295.         myGLCD.print(alarmString, CENTER, 191);
  296.       
  297.       }
  298.       // Clear alarm button
  299.       if ((x >= 215) && (x <= 303) && (y >= 115) && (y <= 145)) {
  300.         drawRectFrame(215, 115, 303, 145);
  301.         alarmString="";
  302.         myGLCD.setColor(0, 0, 0);
  303.         myGLCD.fillRect(45, 165, 275, 210);
  304.       }
  305.       // If we press the MENU Button
  306.       if ((x >= 0) && (x <= 75) && (y >= 0) && (y <= 30)) {
  307.         alarmNotSet = false;
  308.         currentPage = '0';
  309.         myGLCD.clrScr();
  310.         drawHomeScreen();  // Draws the Home Screen
  311.       }   
  312.       }
  313.     }
  314.         
  315.     }
  316.     // Alarm activation     
  317.     if (alarmNotSet == false) {
  318.       if (alarmString == rtc.getTimeStr()){
  319.         myGLCD.clrScr();
  320.         mp3.setVolume(25);
  321.         mp3.playTrackByIndexNumber(1);
  322.         delay(100);
  323.         myGLCD.setFont(BigFont);
  324.         myGLCD.setColor(255, 255, 255);
  325.         myGLCD.print("ALARM", CENTER, 90);
  326.         myGLCD.drawBitmap (127, 10, 65, 64, AlarmButton);
  327.         myGLCD.print(alarmString, CENTER, 114);
  328.         myGLCD.drawRoundRect (94, 146, 226, 170);
  329.         myGLCD.print("DISMISS", CENTER, 150);
  330.         boolean alarmOn = true;
  331.         while (alarmOn){
  332.           if (myTouch.dataAvailable()) {
  333.           myTouch.read();
  334.           x = myTouch.getX(); // X coordinate where the screen has been pressed
  335.           y = myTouch.getY(); // Y coordinates where the screen has been pressed
  336.          
  337.           // Stop alarm button
  338.           if ((x >= 94) && (x <= 226) && (y >= 146) && (y <= 170)) {
  339.           drawRectFrame(94, 146, 226, 170);
  340.           alarmOn = false;
  341.           alarmString="";
  342.           myGLCD.clrScr();
  343.           mp3.stopPlayback();
  344.           delay(100);
  345.           currentPage = '0';
  346.           playStatus = '0';
  347.           mp3.setVolume(15);  
  348.           drawHomeScreen();
  349.           }
  350.       
  351.       }
  352.         }
  353.       }
  354.     }
  355. }
  356. void drawHomeScreen() {
  357.   myGLCD.setBackColor(0, 0, 0); // Sets the background color of the area where the text will be printed to black
  358.   myGLCD.setColor(255, 255, 255); // Sets color to white
  359.   myGLCD.setFont(BigFont); // Sets font to big
  360.   myGLCD.print(rtc.getDateStr(), 153, 7);
  361.   myGLCD.print("T:", 7, 7);
  362.   myGLCD.printNumI(rtc.getTemp(), 39, 7);
  363.   myGLCD.print("C", 82, 7);
  364.   myGLCD.setFont(SmallFont);
  365.   myGLCD.print("o", 74, 5);
  366.   if (alarmString == "" ) {
  367.     myGLCD.setColor(255, 255, 255);
  368.     myGLCD.print("by www.HowToMechatronics.com", CENTER, 215);
  369.   }
  370.   else {
  371.     myGLCD.setColor(255, 255, 255);
  372.     myGLCD.print("Alarm set for: ", 68, 215);
  373.     myGLCD.print(alarmString, 188, 215);
  374.   }
  375.   drawMusicPlayerButton();
  376.   drawAlarmButton();
  377.   drawHomeClock();
  378. }
  379. void drawMusicPlayerScreen() {
  380.   // Title
  381.   myGLCD.setBackColor(0, 0, 0); // Sets the background color of the area where the text will be printed to black
  382.   myGLCD.setColor(255, 255, 255); // Sets color to white
  383.   myGLCD.setFont(BigFont); // Sets font to big
  384.   myGLCD.print("MENU", 5, 5); // Prints the string on the screen
  385.   myGLCD.setColor(255, 0, 0); // Sets color to red
  386.   myGLCD.drawLine(0, 26, 319, 26); // Draws the red line
  387.   myGLCD.setColor(255, 255, 255); // Sets color to white
  388.   myGLCD.setFont(SmallFont); // Sets font to big
  389.   myGLCD.print("by www.HowToMechatronics.com", CENTER, 215); // Prints the string on the screen
  390.   // Volume Bar
  391.   myGLCD.setColor(255, 255, 255);
  392.   myGLCD.fillRect (78, 184, 78 + 150, 184 + 8);
  393.   myGLCD.setColor(240, 196, 30);
  394.   myGLCD.fillRect (78, 184, 78 + 75, 184 + 8);
  395.   // Track Bar
  396.   myGLCD.setColor(255, 255, 255);
  397.   myGLCD.fillRect (48, 50, 48 + 224, 50 + 8);
  398.   myGLCD.setFont(SmallFont);
  399.   myGLCD.setColor(255, 255, 255);
  400.   myGLCD.print("0:00", 8, 48);
  401.   myGLCD.print("-0:00", 276, 48);
  402.   drawPlayButton();
  403.   if (playStatus == '2') {
  404.     drawPauseButton();
  405.   }
  406.   drawPreviousButton();
  407.   drawNextButton();
  408.   drawVolumeDown();
  409.   drawVolumeUp();
  410. }
  411. void drawMusicPlayerButton() {
  412.   myGLCD.drawBitmap (55, 125, 65, 64, MusicPlayerButton);
  413. }
  414. void drawAlarmButton() {
  415.   myGLCD.drawBitmap (195, 125, 65, 64, AlarmButton);
  416. }
  417. void drawPlayButton() {
  418.   myGLCD.drawBitmap (118, 79, 83, 83, ButtonPlay);
  419. }
  420. void drawPauseButton() {
  421.   myGLCD.drawBitmap (118, 79, 83, 83, ButtonPause);
  422. }
  423. void drawNextButton() {
  424.   myGLCD.drawBitmap (227, 97, 50, 50, NextButton);
  425. }
  426. void drawPreviousButton() {
  427.   myGLCD.drawBitmap (45, 97, 50, 50, PreviousButton);
  428. }
  429. void drawVolumeDown() {
  430.   myGLCD.drawBitmap (50, 177, 16, 23, VolumeDown);
  431. }
  432. void drawVolumeUp() {
  433.   myGLCD.drawBitmap (241, 175, 34, 28, VolumeUp);
  434. }
  435. // check for if Mp3 Player is stopped
  436. bool checkFor_mp3IsStopped() {
  437.   if (mp3Serial.available() > 0) {
  438.     if (mp3.getPlaybackStatus() == 0) {
  439.       return true;
  440.     }
  441.   }
  442.   else return false;
  443. }
  444. // Highlights the button when pressed
  445. void drawFrame(int x, int y, int r) {
  446.   myGLCD.setColor(255, 0, 0);
  447.   myGLCD.drawCircle (x, y, r);
  448.   while (myTouch.dataAvailable())
  449.     myTouch.read();
  450.   myGLCD.setColor(0, 0, 0);
  451.   myGLCD.drawCircle (x, y, r);
  452. }
  453. void drawRectFrame(int x1, int y1, int x2, int y2) {
  454.   myGLCD.setColor(255, 0, 0);
  455.   myGLCD.drawRoundRect (x1, y1, x2, y2);
  456.   while (myTouch.dataAvailable())
  457.     myTouch.read();
  458.   myGLCD.setColor(255, 255, 255);
  459.   myGLCD.drawRoundRect (x1, y1, x2, y2);
  460. }
  461. void drawUnderline(int x1, int y1, int x2, int y2) {
  462.   myGLCD.setColor(255, 0, 0);
  463.   myGLCD.drawLine (x1, y1, x2, y2);
  464.   while (myTouch.dataAvailable())
  465.     myTouch.read();
  466.   myGLCD.setColor(0, 0, 0);
  467.   myGLCD.drawLine (x1, y1, x2, y2);
  468. }
  469. // Sound bar
  470. void drawVolume(int x) {
  471.   myGLCD.setColor(255, 255, 255);
  472.   myGLCD.fillRect (78 + 5 * x, 184, 78 + 150, 184 + 8);
  473.   myGLCD.setColor(240, 196, 30);
  474.   myGLCD.fillRect (78, 184, 78 + 5 * x, 184 + 8);
  475. }
  476. // Clears the track bar
  477. void drawTrackBar() {
  478.   myGLCD.setColor(255, 255, 255);
  479.   myGLCD.fillRect (48, 50, 48 + 224, 50 + 8);
  480. }
  481. // Updates the track bar
  482. void trackPlayTime() {
  483.   totalTime = mp3.getTotalTrackPlaybackTime();
  484.   delay(10);
  485.   elapsedTime = mp3.getElapsedTrackPlaybackTime();
  486.   delay(10);
  487.   minutes = (int)elapsedTime / 60;
  488.   seconds = (((float)elapsedTime / 60) - minutes) * 60;
  489.   playback = totalTime - elapsedTime;
  490.   minutesR = (int)playback / 60;
  491.   secondsR = (((float)playback / 60) - minutesR) * 60;
  492.   myGLCD.setFont(SmallFont);
  493.   myGLCD.setColor(255, 255, 255);
  494.   myGLCD.printNumI(minutes, 8, 48);
  495.   myGLCD.print(":", 16, 48);
  496.   myGLCD.printNumI((int)seconds, 24, 48, 2, '0');
  497.   myGLCD.print("-", 276, 48);
  498.   myGLCD.printNumI(minutesR, 284, 48);
  499.   myGLCD.print(":", 292, 48);
  500.   myGLCD.printNumI((int)secondsR, 300, 48, 2, '0');
  501.   int trackBarX = map(elapsedTime, 0, totalTime, 0, 224);
  502.   myGLCD.setColor(255, 0, 0);
  503.   myGLCD.fillRect (48, 50, 48 + trackBarX, 50 + 8);
  504.   if (totalTime == elapsedTime) {
  505.     mp3.nextTrack();
  506.     delay(30);
  507.     myGLCD.setColor(255, 255, 255);
  508.     myGLCD.fillRect (48, 50, 48 + 224, 50 + 8);
  509.   }
  510. }
  511. void printClock(int x, int y) {
  512.   if ( currentClock != rtc.getTimeStr()) {
  513.     myGLCD.print(rtc.getTimeStr(), x, y);
  514.     currentClock = rtc.getTimeStr();
  515.   }
  516. }
  517. void drawColon() {
  518.   myGLCD.setColor(0, 255, 0);
  519.   myGLCD.fillCircle (112, 65, 4);
  520.   myGLCD.setColor(0, 255, 0);
  521.   myGLCD.fillCircle (112, 85, 4);
  522.   myGLCD.setColor(0, 255, 0);
  523.   myGLCD.fillCircle (208, 65, 4);
  524.   myGLCD.setColor(0, 255, 0);
  525.   myGLCD.fillCircle (208, 85, 4);
  526. }
  527. void drawHomeClock() {
  528.   timeString = rtc.getTimeStr();
  529.   currentHours = timeString.substring(0, 2);
  530.   currentMinutes = timeString.substring(3, 5);
  531.   currentSeconds = timeString.substring(6, 8);
  532.   myGLCD.setFont(SevenSegNumFont);
  533.   myGLCD.setColor(0, 255, 0);
  534.   myGLCD.print(currentSeconds, 224, 50);
  535.   myGLCD.print(currentMinutes, 128, 50);
  536.   myGLCD.print(currentHours, 32, 50);
  537.   drawColon();
  538. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 7 小时前

【Arduino 动手做】Arduino触摸屏音乐播放器和闹钟项目

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail