{"id":1888,"date":"2020-11-19T18:31:12","date_gmt":"2020-11-19T23:31:12","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1888"},"modified":"2020-12-10T17:17:24","modified_gmt":"2020-12-10T22:17:24","slug":"fight-alzheimers-disease-with-karaoke","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1888","title":{"rendered":"Fight Alzheimer&#8217;s Disease with Karaoke"},"content":{"rendered":"<h1>Problem<\/h1>\n<p>Alzheimer&#8217;s Disease is an irreversible, progressive brain disorder that slowly destroys memory and thinking skills, and, eventually, the ability to carry out the simplest tasks. Experts suggest that more than 5.5 million Americans, most of them age 65 or older, may have dementia caused by Alzheimer\u2019s. Recent estimates indicate that the disorder is ranked third in the leading cause of death in U.S. With longer life expectancy and larger population, prevention of Alzheimer&#8217;s Disease is no doubt challenging but also necessary.<\/p>\n<p>So far little is known about the cause of Alzheimer&#8217;s Disease, and no evidence has proven any treatment that works for sure. However, the National Academies of Sciences, Engineering, and Medicine (NASEM),\u00a0 found &#8220;encouraging but inconclusive&#8221; evidence for three types of interventions:<\/p>\n<ul>\n<li>\u00a0Increased physical activity<\/li>\n<li>Blood Pressure Control<\/li>\n<li>Cognitive training.<\/li>\n<\/ul>\n<p>Further study shows that informal cognitively stimulating activities, such as reading or playing games, may lower risk of Alzheimer&#8217;s-related cognitive impairment and dementia. In addition, social activity and physical activities also have positive impact for prevention.<\/p>\n<h1>Solution<\/h1>\n<p>I was trying to come up with a device that can encourage the person to engage in social activity, cognitively stimulating activity, and physical activity. Then I thought about the Pokemon Go which you get rewarded by going to different places; I also thought about video games where items can be shared across different devices\/accounts when they are connected, which encourages players to play together.<\/p>\n<p>The device I made is basically a karaoke device that can display lyrics to the screen. An optional microphone is connected with the device through Bluetooth.<\/p>\n<figure id=\"attachment_1957\" aria-describedby=\"caption-attachment-1957\" style=\"width: 840px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" class=\"wp-image-1957 size-large\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3640-1024x651.jpg\" alt=\"\" width=\"840\" height=\"534\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3640-1024x651.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3640-300x191.jpg 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3640-768x488.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3640-1536x977.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3640-2048x1303.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3640-1200x763.jpg 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption id=\"caption-attachment-1957\" class=\"wp-caption-text\">The layout of the device<\/figcaption><\/figure>\n<figure id=\"attachment_1896\" aria-describedby=\"caption-attachment-1896\" style=\"width: 406px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" class=\"wp-image-1896\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/microphone.png\" alt=\"\" width=\"406\" height=\"495\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/microphone.png 499w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/microphone-246x300.png 246w\" sizes=\"(max-width: 406px) 85vw, 406px\" \/><figcaption id=\"caption-attachment-1896\" class=\"wp-caption-text\">The optional Microphone gives the vibe of Karaoke.<\/figcaption><\/figure>\n<p>Learning the song and memorizing lyrics is also an informal cognitively stimulating activity. When the reader has learnt the song and does not need the lyrics anymore, the lyrics can be switched off by the top button.<\/p>\n<p>However, there is no song to play initially. The user can select a music genre and time period once per day to obtain a random song that is in the selected category; to earn more songs, the user has to do some physical exercise such as walking and running for a period . The physical activity is detected by an accelerometer placed in the users&#8217; shoes.<\/p>\n<p>To encourage social activity, songs can be &#8220;shared&#8221; between two users. For example, if I find out that my friend has a song that I would like to have on my device, he can share the song with me. However, it is limited to one shared song per day. There is also a PK feature that allows the user to challenge each other; the two users will sing the same song, and whoever look at the lyrics for the least amount of time wins. The purpose of these mechanism is to make users meet more with their families and friends.<\/p>\n<h1>Proof of Logic<\/h1>\n<h2>Layout<\/h2>\n<figure id=\"attachment_1983\" aria-describedby=\"caption-attachment-1983\" style=\"width: 768px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" class=\"wp-image-1983 size-large\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3642-768x1024.jpg\" alt=\"\" width=\"768\" height=\"1024\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3642-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3642-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3642-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3642-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3642-1200x1600.jpg 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/IMG_3642-scaled.jpg 1920w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><figcaption id=\"caption-attachment-1983\" class=\"wp-caption-text\">The layout of the components of the prototype<\/figcaption><\/figure>\n<p>For this prototype, two Arduinos are used; The one on the left in the photo above is the prototype of the device, and the one on the right is a &#8220;dummy device&#8221; that only sends information through the transceiver. The &#8220;dummy device&#8221; is needed to show the interaction between two device; it is not made into another full prototype because of the lack of materials.<\/p>\n<p>The Arduino of the full prototype connects to a accelerometer, a potentiometer, a mini-mp3 player, 4 buttons, a LCD screen, and a transceiver. The accelerometer detects motion for physical exercise. The potentiometer is for volume control. The mini-mp3 player works with the transducer speaker to play song. The buttons are for the user interface. The LCD screen is to show the user interface and display lyrics when songs are playing. The Transceiver allows communication between the prototype and the &#8220;dummy&#8221; Arduino.<\/p>\n<p>The &#8220;dummy&#8221; Arduino is connected to a button and a transceiver; pressing the button triggers the Arduino to send information through the transceiver. The &#8220;dummy&#8221; Arduino can be powered by an external\u00a0 of a 9V battery. However, it is plugged into PC during testing for convenience of uploading codes.<\/p>\n<h2>Interaction<\/h2>\n<h3>Interface<\/h3>\n<p>The user interface of the prototype includes a LCD screen and four buttons. The first button from the top represents rolling the rotary encoder up, and the second button represents rolling the rotary encoder down. The rotary encoder was labeled &#8220;rotator&#8221; in the sketch of the layout of the device. The third button is the &#8220;Confirm&#8221; button of the rotary encoder, and the fourth button is the &#8220;Back\/Lyrics&#8221; button.<\/p>\n<p>In the following video, the functions of the four buttons are shown by going through the menu. In menu, there are 3 modules to choose: &#8220;Unlocked Songs&#8221;, &#8220;Be Connected&#8221;, and &#8220;Jackpot&#8221;.\u00a0 The first and second button switches the current option.\u00a0 The &#8220;Confirm&#8221; button select the selects option. And the &#8220;Back&#8221; button goes back to the previous stage. Notice that when option &#8220;Unlocked Songs&#8221; was selected in the video, it said empty. It was because there was no unlocked songs yet.<\/p>\n<p><iframe title=\"User interface\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/6X9jiZZZuRo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h3>Jackpot<\/h3>\n<p>The next video shows the option &#8220;Jackpot&#8221;. The user has to select the desired genre and times of the song, then a random song from the selected category will be unlocked. For demonstration purpose, there are only 3 genres (Movie soundtrack, Pop, Jazz) and 2 period (50s, 2010s). Again, the user can only unlock one song per day through jackpot.<\/p>\n<p><iframe title=\"Jackpot\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/iDXy1bCE6lg?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h3>Physical Exercise<\/h3>\n<p>If the user wants to obtain more songs in a day, he\/she can do so by doing physical exercise. An accelerometer can be placed in the user&#8217;s shoe or on user&#8217;s wrist as a fit-band; the physical activity will be detected by the accelerometer. I shook the accelerometer in the video to stimulate the physical activity. After exercising, the user obtains a chance to unlock a song again.<\/p>\n<p><iframe title=\"Exercise\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/IBhKRV032WQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h3>Playing Unlocked Song<\/h3>\n<p>With songs unlocked from the &#8220;Jackpot&#8221;, the user can play the unlocked songs and sing along them. The potentiometer represents the volume control of the device. When the song is being played, the &#8220;Confirm&#8221; button pauses the song and the &#8220;Back\/ Lyrics&#8221; button toggles the lyrics. The lyrics are coded into the prototype because there are better applications to do that.\u00a0 In addition, the potentiometer used in the demonstration does not always have a stable contact with the breadboard, which overwhelms the Arduino with data and makes the buttons less responsive.<\/p>\n<p><iframe title=\"Play unlocked songs\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/5rcKEdBerAA?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h3>Receive Song<\/h3>\n<p>If the user stays in the module of &#8220;Be Connected&#8221; and switches to &#8220;Share Song&#8221; as the current option (but not selecting it), the device can receive a new song from a different device. However, each device can only receive a song from another device once per day. After a receipt, no new song will be added anymore.<\/p>\n<p><iframe title=\"Receive song\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/FDFFEO_y_F4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h3>Share Song<\/h3>\n<p>In the &#8220;Be Connected&#8221; module, if the user selects the option of &#8220;Share Song&#8221; as shown in the video, the user can then choose a n unlocked song to share to a friend. There is no limits on how many songs a device can share per day.<\/p>\n<p><iframe title=\"Share song\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/1I9KY5yWIe8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h3>Compete<\/h3>\n<p>In the module of &#8220;Be Connected&#8221;, the user can select an unlocked song to challenge his\/her friend. When the song is being played, the device keeps track of how long the lyrics is been looked at. When the song finished, the devices will compare the time of showing the lyrics and decide a winner. In the video, the dummy Arduino sends its time of displaying the lyrics after the button was pressed.<\/p>\n<p><iframe title=\"Compete\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/nDe7q2--DxY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h2>Final Notes<\/h2>\n<ul>\n<li>When I started to work on the transceiver, I found out that I did not have enough female-to-male jumper wires. I bought some immediately but they only came the night before the crit, which makes it more stressful than it should be. Next time when I am preparing the components I have to not only think about major devices but all the materials including wires.<\/li>\n<li>There are definitely more rooms for improvement. First of all, the device is designed as a device that downloads music from the internet instead of storing music in a micro-SD card. Some wifi or bluetooth parts should be able to connect the device to the internet. Secondly, the code can be futher optimized. It is cumbersome and inefficient at the point. Thirdly, more games such as guessing the name of the song can be added in addition to the competition of sing without looking at the lyrics. Fourthly, a vibration motor can be added to the device to notify the user when the opponent started to look at lyrics in competition. In addition, the interface can be better with lively sound effects added. For example, before a new song is unlocked, the device can play a little bit of drum rolling. Finally, the device can only became a real karaoke device when a microphone is incorporated.<\/li>\n<\/ul>\n<h2>Schematics<\/h2>\n<figure id=\"attachment_1993\" aria-describedby=\"caption-attachment-1993\" style=\"width: 840px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" class=\"wp-image-1993 size-large\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Prototype-Schematics_schem-1024x590.png\" alt=\"\" width=\"840\" height=\"484\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Prototype-Schematics_schem-1024x590.png 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Prototype-Schematics_schem-300x173.png 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Prototype-Schematics_schem-768x442.png 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Prototype-Schematics_schem-1536x884.png 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Prototype-Schematics_schem-1200x691.png 1200w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Prototype-Schematics_schem.png 1704w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption id=\"caption-attachment-1993\" class=\"wp-caption-text\">Schematics for the full prototype<\/figcaption><\/figure>\n<figure id=\"attachment_1995\" aria-describedby=\"caption-attachment-1995\" style=\"width: 780px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" class=\"wp-image-1995 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Dummy-Schematics-_schem.png\" alt=\"\" width=\"780\" height=\"927\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Dummy-Schematics-_schem.png 780w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Dummy-Schematics-_schem-252x300.png 252w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/Dummy-Schematics-_schem-768x913.png 768w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><figcaption id=\"caption-attachment-1995\" class=\"wp-caption-text\">Schematics for the dummy Arduino<\/figcaption><\/figure>\n<h2>Code<\/h2>\n<p>Code for the full prototype:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">\/\/Library\r\n#include \"Arduino.h\"\r\n#include \"SoftwareSerial.h\"\r\n#include \"DFRobotDFPlayerMini.h\"\r\n#include &lt;Wire.h&gt;\r\n#include &lt;LiquidCrystal_I2C.h&gt;\r\n#include &lt;SPI.h&gt;\r\n#include &lt;nRF24L01.h&gt;\r\n#include &lt;RF24.h&gt;\r\n\r\n\/\/Set up of hardwares\r\n\/\/Mp3 player\r\nSoftwareSerial mySoftwareSerial(6, 7); \/\/ RX, TX\r\nDFRobotDFPlayerMini myDFPlayer;\r\nvoid printDetail(uint8_t type, int value);\r\n\/\/LCD\r\nLiquidCrystal_I2C screen(0x27, 16, 2);\r\n\/\/Transceiver\r\nRF24 radio(8, 9); \/\/ CE, CSN\r\n\r\n\r\n\r\n\/\/Global Variables\r\n\/\/Constant variables\r\nconst int ROTARY_UP = 5;\r\nconst int ROTARY_DOWN = 4;\r\nconst int ROTARY_CONFRIM = 3;\r\nconst int BACK_LYRICS = 2;\r\nconst int VOLUME_CONTROL = A0;\r\nconst int XPIN = A1;\r\nconst int YPIN = A2;\r\nconst int ZPIN = A3;\r\n\r\n\/\/Chaning Variables\r\n\/\/Button\r\nint ButtonState_rotaryUp;\r\nint ButtonState_rotaryDown;\r\nint ButtonState_Confirm;\r\nint ButtonState_Back_Lyrics;\r\n\r\nint lastButtonState_rotaryUp = HIGH;\r\nint lastButtonState_rotaryDown = HIGH;\r\nint lastButtonState_Confirm = HIGH;\r\nint lastButtonState_Back_Lyrics = HIGH;\r\n\r\n\/\/Mp3\r\nint lastVolume = 15;\r\n\r\n\/\/Debounce Varibale\r\nunsigned long lastDebounceTime = 0;  \/\/ the last time the output pin was toggled\r\nunsigned long debounceDelay = 50;    \/\/ the debounce time; increase if the output flickers\r\n\r\n\/\/The variables related to display the lyrics\r\nbool lyrics = false;\r\n\/\/This is for counting the time when lyrics are displayed throughout the song.\r\nunsigned long lyrics_timer_Start;\r\nunsigned long lyrics_time;\r\nunsigned long lyrics_time_oponent;\r\nbool playing = false;\r\n\r\n\/\/Accelerometer\r\nbool timer = false;\r\nunsigned long accelerometer_timer_Start;\r\nunsigned long accelerometer_time;\r\n\/\/Exercise for 10 seconds to get a chance for jackpot\r\nconst unsigned long accelerometer_time_jackpot = 10000;\r\n\r\n\/\/The variables used in building the interface\r\nString interFace = \"Menu\";\r\nString interFace_Secondary;\r\nint interFace_Option = 1;\r\n\r\nString selected_Genre;\r\nString selected_Period;\r\n\r\nint Jackpot_Chance = 1;\r\nunsigned long Jackpot_Clock;\r\nconst int OneDay = 60000;         \/\/For demo purpose 1_Day is 1 minute.\r\n\r\nunsigned long Receive_Clock;\r\nbool song_received = false;\r\n\r\n\/\/Can't read the number of file yet in the global scope so make the array as big as the capacity of the SD card. Or assume the information is already given when the songs are downloaded from internet.\r\n\/\/The sizes of the array are set for the demo purpose\r\n\/\/Arrary that includes all the unlocked songs\r\nint unlocked_Song[5];\r\nint input_indice_unlocked;\r\n\/\/Array taht includes the unlocked 2010s movie soundtrack\r\nint Unlocked_2010s_Movie[1];\r\nint input_indice_movie;\r\nint Unlocked_2010s_Pop[1];\r\nint input_indice_pop;\r\nint Unlocked_50s_Jazz[3];\r\nint input_indice_jazz;\r\n\r\n\/\/Transceiver's addresses\r\n\/\/One for writing and one for reading\r\nconst byte addresses[][6] = {\"00001\", \"00002\"};\r\n\r\n\r\n\/\/Function\r\n\/\/Functions related to the MP3 player\r\nvoid read_information() {\r\n  Serial.println(myDFPlayer.readState()); \/\/read mp3 state\r\n  Serial.println(myDFPlayer.readVolume()); \/\/read current volume\r\n  Serial.println(myDFPlayer.readEQ()); \/\/read EQ setting\r\n  Serial.println(myDFPlayer.readFileCounts()); \/\/read all file counts in SD card\r\n  Serial.println(myDFPlayer.readCurrentFileNumber()); \/\/read current play file number\r\n  \/\/Serial.println(myDFPlayer.readFileCountsInFolder(3)); \/\/read fill counts in folder SD:\/03\r\n}\r\n\r\n\/\/Function related to the transveriver\r\nvoid share_song(int shared_song) {\r\n  radio.stopListening();\r\n  radio.write(&amp;shared_song, sizeof(shared_song));\r\n}\r\n\r\n\/\/Function that receives song from  \"Be connected\"\r\nvoid receive_song() {\r\n  radio.startListening();\r\n  if (radio.available() &amp;&amp; song_received == false ) {\r\n    int shared_song;\r\n    radio.read(&amp;shared_song, sizeof(shared_song));\r\n    \/\/Write the number of the number into the array for unlocked_songs\r\n    unlocked_Song[input_indice_unlocked] = shared_song;\r\n    input_indice_unlocked += 1;\r\n    song_received = true;\r\n    screen.clear();\r\n    screen.setCursor(4, 0);\r\n    screen.print(\"New Song\");\r\n    screen.setCursor(5, 1);\r\n    screen.print(\"Added!\");\r\n    delay(3000);\r\n    screen.clear();\r\n    screen.setCursor(6, 0);\r\n    screen.print(\"Menu\");\r\n    screen.setCursor(1, 1);\r\n    screen.print(\"Unlocked Songs\");\r\n    interFace = \"Menu\";\r\n    interFace_Option = 1;\r\n    radio.stopListening();\r\n  }\r\n}\r\n\r\n\r\n\r\n\/\/Function related to the accelerometer\r\nvoid read_accelerometer() {\r\n  if (timer == false) {\r\n    if (analogRead(ZPIN) &gt; 321) {\r\n      timer = true;\r\n      accelerometer_timer_Start = millis();\r\n    }\r\n  }\r\n  else {\r\n    if (analogRead(ZPIN) &lt;= 321 &amp;&amp; analogRead(ZPIN) &gt;= 317) {\r\n      accelerometer_time += millis() - accelerometer_timer_Start;\r\n      timer = false;\r\n    }\r\n  }\r\n}\r\n\r\n\/\/Functions related to the interface of the device\r\n\/\/Function that checks whether there is an zero in the array, which means there is still song for that category to unlock. (supplemental to function jackpot)\r\nbool CheckforZero(String Genre, String Period) {\r\n  if (Genre == \"Movie\" &amp;&amp; Period == \"2010s\") {\r\n    for (int i = 0; i &lt; (sizeof(Unlocked_2010s_Movie) \/ sizeof(Unlocked_2010s_Movie[0])); i++) {\r\n      if (Unlocked_2010s_Movie[i] == 0) {\r\n        return true;\r\n      }\r\n    }\r\n\r\n  }\r\n\r\n\r\n  else if (Genre == \"Pop\" &amp;&amp; Period == \"2010s\") {\r\n    for (int i = 0; i &lt; (sizeof(Unlocked_2010s_Pop) \/ sizeof(Unlocked_2010s_Pop[0])); i++) {\r\n      if (Unlocked_2010s_Pop[i] == 0) {\r\n        return true;\r\n      }\r\n    }\r\n  }\r\n\r\n  else if (Genre == \"Jazz\" &amp;&amp; Period == \"50s\") {\r\n    for (int i = 0; i &lt; (sizeof(Unlocked_50s_Jazz) \/ sizeof(Unlocked_50s_Jazz[0])); i++) {\r\n      if (Unlocked_50s_Jazz[i] == 0) {\r\n        return true;\r\n      }\r\n    }\r\n  }\r\n\r\n  return false;\r\n  \/\/return false when there is no more 0 in the array\r\n\r\n\r\n}\r\n\r\n\r\n\/\/Function that check whether a number is already in an array. (supplemental to function jackpot)\r\nbool checkNumberinList(int numb, String Genre, String Period) {\r\n  if (Genre == \"Movie\" &amp;&amp; Period == \"2010s\") {\r\n    \/\/Serial.println((sizeof(Unlocked_2010s_Movie) \/ sizeof(Unlocked_2010s_Movie[0])));\r\n    \/\/Serial.println(Unlocked_2010s_Movie[0]);\r\n    for (int i = 0; i &lt; (sizeof(Unlocked_2010s_Movie) \/ sizeof(Unlocked_2010s_Movie[0])); i++) {\r\n      if (Unlocked_2010s_Movie[i] == numb) {\r\n        \/\/Serial.println(\"Here\");\r\n        return true;\r\n      }\r\n    }\r\n  }\r\n\r\n  else if (Genre == \"Pop\" &amp;&amp; Period == \"2010s\") {\r\n    for (int i = 0; i &lt; (sizeof(Unlocked_2010s_Pop) \/ sizeof(Unlocked_2010s_Pop[0])); i++) {\r\n      if (numb == Unlocked_2010s_Pop[i]) {\r\n        return true;\r\n      }\r\n    }\r\n  }\r\n\r\n  else if (Genre == \"Jazz\" &amp;&amp; Period == \"50s\") {\r\n    for (int i = 0; i &lt; (sizeof(Unlocked_50s_Jazz) \/ sizeof(Unlocked_50s_Jazz[0])); i++) {\r\n      if (numb == Unlocked_50s_Jazz[i]) {\r\n        return true;\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\r\n\/\/Function that select a random song to unlock in Jackpot. (supplemental to function button pressed)\r\nint jackpot(String Genre, String Period) {\r\n  \/\/Check if the selected category still has songs in the songbank to unlock\r\n  if (CheckforZero(Genre, Period) != true) {\r\n    \/\/Print the information on the lcd screen\r\n    screen.clear();\r\n    screen.setCursor(1, 0);\r\n    screen.print(String(\"No more \" + Genre));\r\n    screen.setCursor(3, 1);\r\n    screen.print(String(\"in \" + Period));\r\n    delay(5000);\r\n    screen.setCursor(1, 0);\r\n    screen.print(\"Select another\");\r\n    screen.setCursor(2, 1);\r\n    screen.print(\"genre\/period\");\r\n    delay(5000);\r\n    screen.clear();\r\n\r\n    return 0;\r\n  }\r\n\r\n  else {\r\n\r\n    if (Genre == \"Movie\" &amp;&amp; Period == \"2010s\") {\r\n      \/\/Number 1 to number 1 represents Movie Soundtracks in 2010s\r\n      int randomPick = random(1, 2);\r\n\r\n      while (checkNumberinList(randomPick, Genre, Period) == true) {\r\n        randomPick = random(1, 2);\r\n        \/\/Serial.println(randomPick);\r\n      }\r\n      \/\/Add the song into the array of unlocked song\r\n      unlocked_Song[input_indice_unlocked] = randomPick;\r\n      input_indice_unlocked += 1;\r\n\r\n      \/\/Add the song into the array of unlcoked movie soundtrack array\r\n      Unlocked_2010s_Movie[input_indice_movie] = randomPick;\r\n      input_indice_movie += 1;\r\n\r\n\r\n      return randomPick;\r\n    }\r\n\r\n\r\n    else if (Genre == \"Pop\" &amp;&amp; Period == \"2010s\") {\r\n      \/\/Number 1 to number 1 represents Movie Soundtracks in 2010s\r\n      int randomPick = random(2, 3);\r\n      while (checkNumberinList(randomPick, Genre, Period) == true) {\r\n        randomPick = random(2, 3);\r\n      }\r\n      \/\/Add the song into the array of unlocked song\r\n      unlocked_Song[input_indice_unlocked] = randomPick;\r\n      input_indice_unlocked += 1;\r\n\r\n      \/\/Add the song into the array of unlcoked movie soundtrack array\r\n      Unlocked_2010s_Pop[input_indice_pop] = randomPick;\r\n      input_indice_pop += 1;\r\n\r\n      return randomPick;\r\n    }\r\n\r\n    else if (Genre == \"Jazz\" &amp;&amp; Period == \"50s\") {\r\n      \/\/Number 1 to number 1 represents Movie Soundtracks in 2010s\r\n      int randomPick = random(3, 6);\r\n      while (checkNumberinList(randomPick, Genre, Period) == true) {\r\n        randomPick = random(3, 6);\r\n      }\r\n      \/\/Add the song into the array of unlocked song\r\n      unlocked_Song[input_indice_unlocked] = randomPick;\r\n      input_indice_unlocked += 1;\r\n\r\n      \/\/Add the song into the array of unlcoked movie soundtrack array\r\n      Unlocked_50s_Jazz[input_indice_jazz] = randomPick;\r\n      input_indice_jazz += 1;\r\n\r\n      return randomPick;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\/\/Function thats returns the name of the song given the interface_option. (supplemental to function button pressed)\r\nString SongName(int song) {\r\n  if (song == 1) {\r\n    return \"City of Star\";\r\n  }\r\n  else if (song == 2) {\r\n    return \"Stay\";\r\n  }\r\n  else if (song == 3) {\r\n    return \"Fly Me to the Moon\";\r\n  }\r\n  else if (song == 4) {\r\n    return \"All of You\";\r\n  }\r\n  else if (song == 5) {\r\n    return \"The Best is yet to Come\";\r\n  }\r\n}\r\n\r\n\/\/Function that determines what happens when the rotary enocoder is rolled up or down. (supplemental to function button pressed)\r\nvoid Rotary(int input, String pressed_button, int min, int max) {\r\n  if (pressed_button == \"ROTARY_UP\") {\r\n    if (input == 1) {\r\n      interFace_Option = max;\r\n    }\r\n\r\n    else {\r\n      interFace_Option = input - 1;\r\n    }\r\n  }\r\n\r\n  else if (pressed_button == \"ROTARY_DOWN\") {\r\n    if (input == max) {\r\n      interFace_Option = 1;\r\n    }\r\n\r\n    else {\r\n      interFace_Option = input + 1;\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\/\/Function that decide what to do when buttons are pressed. (supplemental to function Read Button)\r\nvoid button_pressed(String pressed_button) {\r\n  \/\/When buttons are pressed at the menu\r\n  if (interFace == \"Menu\") {\r\n    Rotary(interFace_Option, pressed_button, 1, 3);\r\n\r\n    if (pressed_button == \"ROTARY_CONFIRM\") {\r\n      if (interFace_Option == 1) {\r\n        interFace = \"Unlocked Songs\";\r\n        interFace_Secondary = \"Select_Song\";\r\n        interFace_Option = 1;\r\n\r\n      }\r\n\r\n      else if (interFace_Option == 2) {\r\n        interFace = \"Jackpot\";\r\n        \/\/Check if the user has earned a chance for jackpot through exercising\r\n        if (accelerometer_time &gt;= accelerometer_time_jackpot) {\r\n          Serial.println(accelerometer_time);\r\n          Jackpot_Chance += 1;\r\n          accelerometer_time = 0;\r\n        }\r\n        if (Jackpot_Chance == 0) {\r\n          \/\/No more chance to get a new song for the day through Jackpot\r\n          interFace_Secondary = \"NoMore\";\r\n        }\r\n        else {\r\n          interFace_Secondary = \"Genre\";\r\n        }\r\n        interFace_Option = 1;\r\n\r\n      }\r\n\r\n      else if (interFace_Option == 3) {\r\n        interFace = \"Be Connected\";\r\n        interFace_Option = 1;\r\n        interFace_Secondary = \"Receive\";\r\n      }\r\n    }\r\n\r\n    \/\/Display the options in Menu to the LCD screen\r\n    \/\/Clear the screen first\r\n    screen.clear();\r\n    if (interFace == \"Menu\") {\r\n      screen.setCursor(6, 0);\r\n      screen.print(\"Menu\");\r\n      if (interFace_Option == 1) {\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"Unlocked Songs\");\r\n      }\r\n      else if (interFace_Option == 2) {\r\n        screen.setCursor(4, 1);\r\n        screen.print(\"Jackpot\");\r\n      }\r\n      else if (interFace_Option == 3) {\r\n        screen.setCursor(2, 1);\r\n        screen.print(\"Be Connected\");\r\n      }\r\n    }\r\n    else if (interFace == \"Unlocked Songs\") {\r\n      screen.setCursor(1, 0);\r\n      screen.print(\"Unlocked Songs\");\r\n      if (unlocked_Song[interFace_Option - 1] == 0) {\r\n        screen.setCursor(5, 1);\r\n        screen.print(\"Empty\");\r\n        delay(3000);\r\n        screen.clear();\r\n        screen.setCursor(6, 0);\r\n        screen.print(\"Menu\");\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"Unlocked Songs\");\r\n        interFace = \"Menu\";\r\n        interFace_Option = 1;\r\n      }\r\n\r\n      else {\r\n        int song = unlocked_Song[interFace_Option - 1];\r\n        screen.setCursor((16 - SongName(song).length()) \/ 2, 1);\r\n        screen.print(SongName(song));\r\n      }\r\n    }\r\n    else if (interFace == \"Jackpot\") {\r\n      if (interFace_Secondary == \"NoMore\") {\r\n        screen.setCursor(2, 0);\r\n        screen.print(\"Unavailable\");\r\n        screen.setCursor(3, 1);\r\n        screen.print(\"Right now\");\r\n        delay(3000);\r\n        screen.clear();\r\n        screen.setCursor(1, 0);\r\n        screen.print(\"Earn More Song\");\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"by exercising\");\r\n        delay(3000);\r\n        screen.clear();\r\n        screen.setCursor(2, 0);\r\n        screen.print(\"and meeting\");\r\n        screen.setCursor(4, 1);\r\n        screen.print(\"friends!\");\r\n        delay(3000);\r\n        \/\/Goes back the menu page\r\n        screen.clear();\r\n        interFace = \"Menu\";\r\n        interFace_Option = 1;\r\n        screen.setCursor(6, 0);\r\n        screen.print(\"Menu\");\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"Unlocked Songs\");\r\n\r\n      }\r\n\r\n\r\n      else  {\r\n        screen.setCursor(5, 0);\r\n        screen.print(\"Genre\");\r\n        screen.setCursor(5, 1);\r\n        screen.print(\"Movie\");\r\n      }\r\n    }\r\n\r\n    else if (interFace == \"Be Connected\") {\r\n      screen.setCursor(2, 0);\r\n      screen.print(\"Be Connected\");\r\n      screen.setCursor(3, 1);\r\n      screen.print(\"Share Song\");\r\n    }\r\n  }\r\n\r\n  \/\/When buttons are pressed at Unlocked Songs\r\n  else if (interFace == \"Unlocked Songs\") {\r\n    if (interFace_Secondary == \"Select_Song\") {\r\n      Rotary(interFace_Option, pressed_button, 1, input_indice_unlocked);\r\n\r\n\r\n      if (pressed_button == \"ROTARY_CONFIRM\") {\r\n        myDFPlayer.play(unlocked_Song[interFace_Option - 1]);\r\n\r\n        interFace_Secondary = \"Playing_song\";\r\n        playing = true;\r\n        screen.clear();\r\n      }\r\n\r\n      else if (pressed_button == \"BACK_LYRICS\") {\r\n        interFace = \"Menu\";\r\n        interFace_Option = 1;\r\n        screen.clear();\r\n        screen.setCursor(6, 0);\r\n        screen.print(\"Menu\");\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"Unlocked Songs\");\r\n\r\n      }\r\n    }\r\n\r\n    else if (interFace_Secondary == \"Playing_song\") {\r\n      if (pressed_button == \"ROTARY_CONFIRM\") {\r\n        playing = !playing;\r\n        if (playing == false) {\r\n          Serial.println(\"pause\");\r\n          myDFPlayer.pause();\r\n        }\r\n        else {\r\n          myDFPlayer.start();\r\n        }\r\n      }\r\n\r\n      else if (pressed_button == \"BACK_LYRICS\") {\r\n        \/\/Serial.println(myDFPlayer.readState());\r\n        \/\/This means the song is finished\r\n        if (myDFPlayer.readState() == 512) {\r\n          if (lyrics == true) {\r\n            lyrics = false;\r\n          }\r\n\r\n          interFace = \"Menu\";\r\n          interFace_Option = 1;\r\n          screen.clear();\r\n          interFace = \"Menu\";\r\n          interFace_Option = 1;\r\n          screen.setCursor(6, 0);\r\n          screen.print(\"Menu\");\r\n          screen.setCursor(1, 1);\r\n          screen.print(\"Unlocked Songs\");\r\n        }\r\n        else {\r\n          lyrics = !lyrics;\r\n          \/\/Serial.println(lyrics);\r\n          if (lyrics == true) {\r\n\r\n            screen.setCursor(5, 0);\r\n            screen.print(\"Lyrics\");\r\n            screen.setCursor(5, 1);\r\n            screen.print(\"Lyrics\");\r\n          }\r\n          else {\r\n            screen.clear();\r\n            \/\/Add the lyrics-displaying time to the sum\r\n\r\n          }\r\n        }\r\n      }\r\n    }\r\n\r\n    \/\/Display the options in Menu to the LCD screen\r\n    \/\/Clear the screen first\r\n\r\n    if (interFace == \"Unlocked Songs\") {\r\n      if (unlocked_Song[0] == 0) {\r\n        screen.clear();\r\n        screen.setCursor(1, 0);\r\n        screen.print(\"Unlocked Songs\");\r\n        screen.setCursor(5, 1);\r\n        screen.print(\"Empty\");\r\n      }\r\n\r\n      else if (interFace_Secondary == \"Select_Song\") {\r\n        int song = unlocked_Song[interFace_Option - 1];\r\n        \/\/Serial.println(\"Hello\");\r\n        screen.clear();\r\n        screen.setCursor(1, 0);\r\n        screen.print(\"Unlocked Songs\");\r\n        screen.setCursor((16 - SongName(song).length()) \/ 2, 1);\r\n        screen.print(SongName(song));\r\n      }\r\n    }\r\n    else if (interFace == \"Menu\") {\r\n      screen.clear();\r\n      screen.setCursor(6, 0);\r\n      screen.print(\"Menu\");\r\n      if (interFace_Option == 1) {\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"Unlocked Songs\");\r\n      }\r\n    }\r\n  }\r\n\r\n  \/\/When buttons are pressed at Jackpot\r\n  else if (interFace == \"Jackpot\") {\r\n    \/\/Selecting the Genre of the music of jackpot\r\n    if (interFace_Secondary == \"Genre\") {\r\n      Rotary(interFace_Option, pressed_button, 1, 3);\r\n\r\n\r\n      if (pressed_button == \"ROTARY_CONFIRM\") {\r\n        if (interFace_Option == 1) {\r\n          selected_Genre = \"Movie\";\r\n        }\r\n\r\n        else if (interFace_Option == 2) {\r\n          selected_Genre = \"Jazz\";\r\n        }\r\n\r\n        else if (interFace_Option == 3) {\r\n          selected_Genre = \"Pop\";\r\n        }\r\n\r\n        interFace_Secondary = \"Period\";\r\n        interFace_Option = 1;\r\n        \/\/Serial.println(selected_Genre);\r\n\r\n      }\r\n\r\n      else if (pressed_button == \"BACK_LYRICS\") {\r\n        interFace = \"Menu\";\r\n        interFace_Option = 1;\r\n      }\r\n\r\n      \/\/Display the options in Menu to the LCD screen\r\n      \/\/Clear the screen first\r\n      screen.clear();\r\n      if (interFace == \"Menu\") {\r\n        screen.setCursor(6, 0);\r\n        screen.print(\"Menu\");\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"Unlocked Songs\");\r\n      }\r\n      else if (interFace_Secondary == \"Period\") {\r\n        screen.setCursor(5, 0);\r\n        screen.print(\"Period\");\r\n        screen.setCursor(5, 1);\r\n        screen.print(\"2010s\");\r\n      }\r\n\r\n      else {\r\n        screen.setCursor(5, 0);\r\n        screen.print(\"Genre\");\r\n        if (interFace_Option == 1) {\r\n          screen.setCursor(5, 1);\r\n          screen.print(\"Movie\");\r\n        }\r\n\r\n        else if (interFace_Option == 2) {\r\n          screen.setCursor(6, 1);\r\n          screen.print(\"Jazz\");\r\n        }\r\n\r\n        else if (interFace_Option == 3) {\r\n          screen.setCursor(6, 1);\r\n          screen.print(\"Pop\");\r\n        }\r\n      }\r\n    }\r\n\r\n    \/\/Selecting the Period\r\n    else if (interFace_Secondary == \"Period\") {\r\n      Rotary(interFace_Option, pressed_button, 1, 2);\r\n\r\n\r\n      if (pressed_button == \"ROTARY_CONFIRM\") {\r\n        if (interFace_Option == 1) {\r\n          selected_Period = \"2010s\";\r\n          \/\/When there is no more songs in the selected category to unlock\r\n        }\r\n        else if (interFace_Option == 2) {\r\n          selected_Period = \"50s\";\r\n        }\r\n\r\n        int song = jackpot(selected_Genre, selected_Period);\r\n        if (song == 0) {\r\n          \/\/Go back to choose another genre\r\n          interFace_Secondary = \"Genre\";\r\n          interFace_Option = 1;\r\n          screen.setCursor(5, 0);\r\n          screen.print(\"Genre\");\r\n          screen.setCursor(5, 1);\r\n          screen.print(\"Movie\");\r\n          return;\r\n        }\r\n        else {\r\n          \/\/Serial.println(jackpot(selected_Genre, selected_Period));\r\n          Jackpot_Chance -= 1;\r\n          screen.clear();\r\n          screen.setCursor(4, 0);\r\n          screen.print(\"Jackpot!\");\r\n          String Acquired_Song = SongName(song);\r\n          screen.setCursor((16 - Acquired_Song.length()) \/ 2, 1);\r\n          screen.print(Acquired_Song);\r\n          delay(2000);\r\n          \/\/Returns to the Menu page\r\n          interFace = \"Menu\";\r\n          interFace_Option = 1;\r\n          screen.clear();\r\n          screen.setCursor(6, 0);\r\n          screen.print(\"Menu\");\r\n          screen.setCursor(1, 1);\r\n          screen.print(\"Unlocked Songs\");\r\n          return;\r\n        }\r\n      }\r\n\r\n      else if (pressed_button == \"BACK_LYRICS\") {\r\n        interFace_Secondary = \"Genre\";\r\n        interFace_Option = 1;\r\n      }\r\n\r\n      \/\/Display the options in Menu to the LCD screen\r\n      \/\/Clear the screen first\r\n      screen.clear();\r\n      if (interFace_Secondary == \"Genre\") {\r\n        screen.setCursor(5, 0);\r\n        screen.print(\"Genre\");\r\n        screen.setCursor(5, 1);\r\n        screen.print(\"Movie\");\r\n      }\r\n      else {\r\n        screen.setCursor(5, 0);\r\n        screen.print(\"Period\");\r\n        if (interFace_Option == 1) {\r\n          screen.setCursor(5, 1);\r\n          screen.print(\"2010s\");\r\n        }\r\n\r\n        else if (interFace_Option == 2) {\r\n          screen.setCursor(6, 1);\r\n          screen.print(\"50s\");\r\n        }\r\n      }\r\n    }\r\n  }\r\n\r\n  \/\/When the interface is Be Connected\r\n  else if (interFace == \"Be Connected\") {\r\n    if (interFace_Secondary == \"Receive\") {\r\n      Rotary(interFace_Option, pressed_button, 1, 2);\r\n\r\n      if (pressed_button == \"ROTARY_CONFIRM\") {\r\n        if (interFace_Option == 1) {\r\n          interFace_Secondary = \"share_song\";\r\n          interFace_Option = 1;\r\n        }\r\n\r\n        else if (interFace_Option == 2) {\r\n          interFace_Secondary = \"compete\";\r\n          interFace_Option = 1;\r\n        }\r\n      }\r\n\r\n\r\n      else if (pressed_button == \"BACK_LYRICS\") {\r\n        interFace = \"Menu\";\r\n        interFace_Option = 1;\r\n      }\r\n\r\n      \/\/lcd display\r\n      screen.clear();\r\n      if (interFace == \"Menu\") {\r\n        screen.clear();\r\n        screen.setCursor(6, 0);\r\n        screen.print(\"Menu\");\r\n        screen.setCursor(1, 1);\r\n        screen.print(\"Unlocked Songs\");\r\n      }\r\n      else if (interFace_Secondary == \"Receive\") {\r\n        screen.setCursor(2, 0);\r\n        screen.print(\"Be Connected\");\r\n        if (interFace_Option == 1) {\r\n          screen.setCursor(3, 1);\r\n          screen.print(\"Share Song\");\r\n        }\r\n        else if (interFace_Option == 2) {\r\n          screen.setCursor(4, 1);\r\n          screen.print(\"Compete\");\r\n        }\r\n      }\r\n\r\n      else if (interFace_Secondary == \"share_song\") {\r\n        screen.setCursor(3, 0);\r\n        screen.print(\"Share Song\");\r\n        if (unlocked_Song[0] == 0) {\r\n          screen.setCursor(5, 1);\r\n          screen.print(\"Empty\");\r\n          delay(2000);\r\n          interFace_Secondary = \"Receive\";\r\n          interFace_Option = 1;\r\n          screen.setCursor(2, 0);\r\n          screen.print(\"Be Connected\");\r\n          screen.setCursor(3, 1);\r\n          screen.print(\"Share Song\");\r\n        }\r\n\r\n        else {\r\n          int song = unlocked_Song[interFace_Option - 1];\r\n          \/\/Serial.println(\"Hello\");\r\n          screen.setCursor((16 - SongName(song).length()) \/ 2, 1);\r\n          screen.print(SongName(song));\r\n        }\r\n      }\r\n\r\n      else if (interFace_Secondary == \"compete\") {\r\n        screen.setCursor(4, 0);\r\n        screen.print(\"Compete\");\r\n        if (unlocked_Song[0] == 0) {\r\n          screen.setCursor(5, 1);\r\n          screen.print(\"Empty\");\r\n          delay(2000);\r\n          interFace_Secondary = \"Receive\";\r\n          interFace_Option = 1;\r\n          screen.setCursor(2, 0);\r\n          screen.print(\"Be Connected\");\r\n          screen.setCursor(3, 1);\r\n          screen.print(\"Share Song\");\r\n        }\r\n\r\n        else {\r\n          int song = unlocked_Song[interFace_Option - 1];\r\n          \/\/Serial.println(\"Hello\");\r\n          screen.setCursor((16 - SongName(song).length()) \/ 2, 1);\r\n          screen.print(SongName(song));\r\n        }\r\n      }\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n    }\r\n\r\n    else if (interFace_Secondary == \"Playing_song\") {\r\n      if (pressed_button == \"ROTARY_CONFIRM\") {\r\n        playing = !playing;\r\n        if (playing == false) {\r\n          Serial.println(\"pause\");\r\n          myDFPlayer.pause();\r\n        }\r\n        else {\r\n          myDFPlayer.start();\r\n        }\r\n      }\r\n\r\n      else if (pressed_button == \"BACK_LYRICS\") {\r\n        \/\/Serial.println(myDFPlayer.readState());\r\n        \/\/This means the song is finished\r\n        if (myDFPlayer.readState() == 512) {\r\n          if (lyrics == true) {\r\n            lyrics_time += millis() - lyrics_timer_Start;\r\n            lyrics = false;\r\n          }\r\n\r\n          \/\/Send and receive the lyrics_time, then determines who wins\r\n          radio.stopListening();\r\n          radio.write(&amp;lyrics_time, sizeof(lyrics_time));\r\n          radio.startListening();\r\n          while (!radio.available()); \/\/wait until the lyrics_time of the opponenet was received\r\n          radio.read(&amp;lyrics_time_oponent , sizeof(lyrics_time_oponent));\r\n\r\n          if (lyrics_time &lt;= lyrics_time_oponent) {\r\n            screen.setCursor(4, 0);\r\n            screen.print(\"You Win!\");\r\n            screen.setCursor(2, 1);\r\n            screen.print(\"Great Work!\");\r\n          }\r\n          else {\r\n            screen.setCursor(4, 0);\r\n            screen.print(\"You Lose\");\r\n          }\r\n          delay(5000);\r\n          lyrics_time = 0;\r\n          lyrics_time_oponent = 0;\r\n\r\n          \/\/Goes back to the menu\r\n          interFace = \"Menu\";\r\n          interFace_Option = 1;\r\n          screen.clear();\r\n          interFace = \"Menu\";\r\n          interFace_Option = 1;\r\n          screen.setCursor(6, 0);\r\n          screen.print(\"Menu\");\r\n          screen.setCursor(1, 1);\r\n          screen.print(\"Unlocked Songs\");\r\n        }\r\n        else {\r\n          Serial.println(\"Lyrics\");\r\n          lyrics = !lyrics;\r\n          \/\/Serial.println(lyrics);\r\n          if (lyrics == true) {\r\n            lyrics_timer_Start = millis();\r\n            screen.setCursor(5, 0);\r\n            screen.print(\"Lyrics\");\r\n            screen.setCursor(5, 1);\r\n            screen.print(\"Lyrics\");\r\n          }\r\n          else {\r\n            screen.clear();\r\n            \/\/Add the lyrics-displaying time to the sum\r\n            lyrics_time += millis() - lyrics_timer_Start;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    \/\/Instead of receiving information, either sharing song or competing\r\n    else {\r\n      Rotary(interFace_Option, pressed_button, 1, input_indice_unlocked);\r\n\r\n\r\n      if (pressed_button == \"ROTARY_CONFIRM\") {\r\n        \/\/Sending the number of the song through transceiver\r\n        if (interFace_Secondary == \"share_song\") {\r\n          int song = unlocked_Song[interFace_Option - 1];\r\n          share_song(song);\r\n          \/\/lcd displays the song shared confirmation\r\n          \/\/Serial.println(\"Here\");\r\n          screen.clear();\r\n          screen.setCursor(6, 0);\r\n          screen.print(\"Song\");\r\n          screen.setCursor(4, 1);\r\n          screen.print(\"Shared!\");\r\n          delay(2000);\r\n          interFace_Secondary = \"Receive\";\r\n          interFace_Option = 1;\r\n        }\r\n\r\n        \/\/For competing\r\n        else if (interFace_Secondary == \"compete\") {\r\n          int song = unlocked_Song[interFace_Option - 1];\r\n          share_song(song);\r\n          myDFPlayer.play(unlocked_Song[interFace_Option - 1]);\r\n\r\n          interFace_Secondary = \"Playing_song\";\r\n          playing = true;\r\n\r\n          screen.clear();\r\n        }\r\n      }\r\n\r\n      else if (pressed_button == \"BACK_LYRICS\") {\r\n        interFace_Secondary = \"Receive\";\r\n        interFace_Option = 1;\r\n      }\r\n\r\n      \/\/lcd display\r\n      screen.clear();\r\n      if (interFace_Secondary == \"Receive\") {\r\n        screen.setCursor(2, 0);\r\n        screen.print(\"Be Connected\");\r\n        screen.setCursor(3, 1);\r\n        screen.print(\"Share Song\");\r\n      }\r\n\r\n      else if (interFace_Secondary != \"Playing_song\") {\r\n        if (interFace_Secondary == \"share_song\") {\r\n          screen.setCursor(3, 0);\r\n          screen.print(\"Share Song\");\r\n        }\r\n        else if (interFace_Secondary == \"compete\") {\r\n          screen.setCursor(4, 0);\r\n          screen.print(\"Compete\");\r\n        }\r\n        int song = unlocked_Song[interFace_Option - 1];\r\n        screen.setCursor((16 - SongName(song).length()) \/ 2, 1);\r\n        screen.print(SongName(song));\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n\r\n\/\/Function that read the pressing of the buttons\r\nvoid read_buttons() {\r\n  \/\/Read Potentiometer and adjust the volume\r\n  int potVal = analogRead(VOLUME_CONTROL);\r\n  int currentVolume = map(potVal, 0, 1023, 0, 30);\r\n\r\n  if (currentVolume != lastVolume) {\r\n    \/\/Serial.println(currentVolume);\r\n    myDFPlayer.volume(currentVolume);\r\n    lastVolume = currentVolume;\r\n  }\r\n\r\n  \/\/Reading the buttons (with debounce)\r\n  int reading_Up = digitalRead(ROTARY_UP);\r\n  int reading_Down = digitalRead(ROTARY_DOWN);\r\n  int reading_Confirm = digitalRead(ROTARY_CONFRIM);\r\n  int reading_back_Lyrics = digitalRead(BACK_LYRICS);\r\n\r\n  if (reading_Up != lastButtonState_rotaryUp || reading_Down != lastButtonState_rotaryDown || reading_Confirm != lastButtonState_Confirm || reading_back_Lyrics != lastButtonState_Back_Lyrics) {\r\n    \/\/ reset the debouncing timer\r\n    lastDebounceTime = millis();\r\n  }\r\n\r\n  if ((millis() - lastDebounceTime) &gt; debounceDelay) {\r\n    \/\/ whatever the reading is at, it's been there for longer than the debounce\r\n    \/\/ delay, so take it as the actual current state:\r\n\r\n    \/\/Rotary up button\r\n    \/\/ if the button state has changed:\r\n    if (reading_Up != ButtonState_rotaryUp) {\r\n      ButtonState_rotaryUp = reading_Up;\r\n\r\n      if (ButtonState_rotaryUp == LOW) {\r\n        \/\/Serial.println(interFace_Option);\r\n        Serial.println(\"Rotary Up\");\r\n        button_pressed(\"ROTARY_UP\");\r\n        Serial.println(interFace_Option);\r\n      }\r\n    }\r\n\r\n    \/\/Rotary Down Button\r\n    if (reading_Down != ButtonState_rotaryDown) {\r\n      ButtonState_rotaryDown = reading_Down;\r\n\r\n      if (ButtonState_rotaryDown == LOW) {\r\n        Serial.println(\"Rotary Down\");\r\n        button_pressed(\"ROTARY_DOWN\");\r\n        Serial.println(interFace_Option);\r\n      }\r\n    }\r\n\r\n    \/\/Rotary Confirm Button\r\n    if (reading_Confirm != ButtonState_Confirm) {\r\n      ButtonState_Confirm = reading_Confirm;\r\n\r\n      if (ButtonState_Confirm == LOW) {\r\n        Serial.println(\"Confirm\");\r\n        button_pressed(\"ROTARY_CONFIRM\");\r\n        Serial.println(interFace);\r\n      }\r\n    }\r\n\r\n    \/\/Back or show lyric Button\r\n    if (reading_back_Lyrics != ButtonState_Back_Lyrics) {\r\n      ButtonState_Back_Lyrics = reading_back_Lyrics;\r\n\r\n      if (ButtonState_Back_Lyrics == LOW) {\r\n        Serial.println(\"Back or show lyrics\");\r\n        button_pressed(\"BACK_LYRICS\");\r\n        Serial.println(interFace);\r\n      }\r\n    }\r\n  }\r\n\r\n\r\n  \/\/ save the readinga. Next time through the loop, they'll be the lastButtonState:\r\n  lastButtonState_rotaryUp = reading_Up;\r\n  lastButtonState_rotaryDown = reading_Down;\r\n  lastButtonState_Confirm = reading_Confirm;\r\n  lastButtonState_Back_Lyrics = reading_back_Lyrics;\r\n}\r\n\r\n\r\n\/\/Setup Function\r\nvoid setup()\r\n{\r\n  \/\/For the mp3 player\r\n  mySoftwareSerial.begin(9600);\r\n  Serial.begin(115200);\r\n\r\n\r\n  if (!myDFPlayer.begin(mySoftwareSerial)) {  \/\/Use softwareSerial to communicate with mp3.\r\n    Serial.println(F(\"Unable to begin:\"));\r\n    Serial.println(F(\"1.Please recheck the connection!\"));\r\n    Serial.println(F(\"2.Please insert the SD card!\"));\r\n    while (true);\r\n  }\r\n  Serial.println(F(\"DFPlayer Mini online.\"));\r\n\r\n  \/\/For the LCD screen\r\n  screen.init();\r\n  screen.backlight();\r\n\r\n\r\n  \/\/Set serial communictaion time out 500ms\r\n  myDFPlayer.setTimeOut(500);\r\n  \/\/----Set volume----\r\n  myDFPlayer.volume(15);  \/\/Set volume value (0~30).\r\n  \/\/----Set different EQ----\r\n  myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);\r\n  \/\/----Set device we use SD as default----\r\n  myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);\r\n\r\n\r\n  \/\/Setting up the pins (buttons)\r\n  pinMode(ROTARY_UP, INPUT_PULLUP);\r\n  pinMode(ROTARY_DOWN, INPUT_PULLUP);\r\n  pinMode(ROTARY_CONFRIM, INPUT_PULLUP);\r\n  pinMode(BACK_LYRICS, INPUT_PULLUP);\r\n  pinMode(XPIN, INPUT);\r\n  pinMode(YPIN, INPUT);\r\n  pinMode(ZPIN, INPUT);\r\n\r\n  \/\/Initial Display on the lcd for the menu\r\n  screen.setCursor(4, 0);\r\n  screen.print(\"Welcome\");\r\n  delay(1500);\r\n  screen.clear();\r\n  screen.setCursor(6, 0);\r\n  screen.print(\"Menu\");\r\n  screen.setCursor(1, 1);\r\n  screen.print(\"Unlocked Songs\");\r\n\r\n  \/\/Set up the transceiver\r\n  radio.begin();\r\n  radio.openWritingPipe(addresses[1]); \/\/ 00002\r\n  radio.openReadingPipe(1, addresses[0]); \/\/ 00001\r\n  radio.setPALevel(RF24_PA_MIN);\r\n\r\n\r\n\r\n  \/\/Test ground\r\n  \/\/Serial.println(Unlocked_2010s_Movie[0]);\r\n  \/\/myDFPlayer.play(1);\r\n  \/\/read_information();\r\n}\r\n\r\nvoid loop()\r\n{\r\n  \/\/Check if it is already 1 day after the last Jackpot. If so, add 1 chance to jackpot.\r\n  if (millis() - Jackpot_Clock &gt; OneDay) {\r\n    accelerometer_time = 0;\r\n    Jackpot_Chance += 1;\r\n    Jackpot_Clock = millis();\r\n  }\r\n\r\n  \/\/Check if it is already 1 day after the last reception of song. If so, allow reception again.\r\n  if (millis() - Receive_Clock &gt; OneDay) {\r\n    song_received = false;\r\n    Receive_Clock = millis();\r\n  }\r\n\r\n\r\n  \/\/Update the interface according to the inputs\r\n  read_accelerometer();\r\n  read_buttons();\r\n\r\n  \/\/Check if there is song being shared to receive\r\n  if (interFace == \"Be Connected\") {\r\n    \/\/Song_received is the bool variable that check whether a reception has already occured \r\n    if (interFace_Secondary == \"Receive\" &amp;&amp; song_received == false) {\r\n      if (interFace_Option == 1) {\r\n        receive_song();\r\n      }\r\n    }\r\n  }\r\n}<\/pre>\n<p>Code for the &#8220;Dummy Arduino&#8221;:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">\/\/Library\r\n#include &lt;SPI.h&gt;\r\n#include &lt;nRF24L01.h&gt;\r\n#include &lt;RF24.h&gt;\r\nRF24 radio(8, 9); \/\/ CE, CSN\r\n\r\n\/\/Addresses for transceriver\r\nconst byte addresses[][6] = {\"00001\", \"00002\"};\r\n\r\n\/\/Variables for the button \r\nconst int BUTTONPIN = 7;\r\nint buttonState;             \r\nint lastButtonState = HIGH; \r\n\r\n\/\/For debouncing\r\nunsigned long lastDebounceTime = 0;  \r\nunsigned long debounceDelay = 50; \r\n\r\n\/\/Change this to 1-5 for sharing songs. Any number for stimulating the competition.\r\nint shared_song = 100000;\r\n\r\n\/\/Function to send a integer representing a song through transceiver. It can be used to send int for any purpose. \r\nvoid share_song() {\r\n  radio.stopListening();\r\n  radio.write(&amp;shared_song, sizeof(shared_song));\r\n  shared_song += 1;\r\n  Serial.println(\"Shared\");\r\n}\r\n\r\nvoid setup() {\r\n  radio.begin();\r\n  radio.openWritingPipe(addresses[0]); \/\/ 00002\r\n  radio.openReadingPipe(1,addresses[1]); \/\/ 00001\r\n  radio.setPALevel(RF24_PA_MIN);\r\n  \r\n  pinMode(BUTTONPIN, INPUT_PULLUP);\r\n}\r\n\r\n\r\nvoid loop() {\r\n  \/*\r\n  int song = 1;\r\n  radio.write(&amp;song, sizeof(song));\r\n  delay(1000);\r\n  *\/\r\n\r\n   int reading = digitalRead(BUTTONPIN);\r\n\r\n\r\n  \/\/ If the switch changed, due to noise or pressing:\r\n  if (reading != lastButtonState) {\r\n    \/\/ reset the debouncing timer\r\n    lastDebounceTime = millis();\r\n  }\r\n\r\n  if ((millis() - lastDebounceTime) &gt; debounceDelay) {\r\n    \/\/ whatever the reading is at, it's been there for longer than the debounce\r\n    \/\/ delay, so take it as the actual current state:\r\n\r\n    \/\/ if the button state has changed:\r\n    if (reading != buttonState) {\r\n      buttonState = reading;\r\n\r\n      \r\n      if (buttonState == LOW) {\r\n        share_song();\r\n      }\r\n    }\r\n  }\r\n  lastButtonState = reading;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Alzheimer&#8217;s Disease is an irreversible, progressive brain disorder that slowly destroys memory and thinking skills, and, eventually, the ability to carry out the simplest tasks. Experts suggest that more than 5.5 million Americans, most of them age 65 or older, may have dementia caused by Alzheimer\u2019s. Recent estimates indicate that the disorder is ranked &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=1888\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fight Alzheimer&#8217;s Disease with Karaoke&#8221;<\/span><\/a><\/p>\n","protected":false},"author":24,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1888"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1888"}],"version-history":[{"count":15,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1888\/revisions"}],"predecessor-version":[{"id":2003,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/1888\/revisions\/2003"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}