{"id":2411,"date":"2022-03-26T11:16:04","date_gmt":"2022-03-26T15:16:04","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2411"},"modified":"2022-04-04T16:10:15","modified_gmt":"2022-04-04T20:10:15","slug":"assignment-7-sound-that-has-meaning","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2411","title":{"rendered":"Assignment 7: Sound that has meaning"},"content":{"rendered":"<h2>Description:<\/h2>\n<p>This project was meant to convey emotions through sound by playing a song corresponding to the user&#8217;s emotions when a button is pressed. Currently there are only 3 buttons for 3 different sounds\/songs but the idea is to be able to hook up more and more as songs stick out as conveying your emotions. The main components for this build are buttons, resistors, a speaker and amplifier, and the Teensy 4.1. When each button is pressed, a certain song corresponding to a different emotion will start to play through. When the song is over, it waits for the next button to be pressed and does not repeat the current sound. When each button is pressed, the current song being played will stop playing and switch to the next song corresponding to the button press. As of now, button 0 plays the Jaws intense sound that signifies a stress and anxiety. Button 1 plays an African Safari game sound that signifies being happy and adventurous. Button 2 plays a relaxing song to convey peace and relaxation.<\/p>\n<h2>Video:<\/h2>\n<p><a href=\"https:\/\/drive.google.com\/file\/d\/1CMMD9j9sRveaiGJDtseF089ZUQ_BY7ep\/view?usp=sharing\">Demo Video<\/a><\/p>\n<h2>Images:<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-2430 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Overall-Image-Assignment-7-1-scaled-e1648305843625.jpg\" alt=\"\" width=\"1881\" height=\"1760\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Overall-Image-Assignment-7-1-scaled-e1648305843625.jpg 1881w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Overall-Image-Assignment-7-1-scaled-e1648305843625-300x281.jpg 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Overall-Image-Assignment-7-1-scaled-e1648305843625-1024x958.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Overall-Image-Assignment-7-1-scaled-e1648305843625-768x719.jpg 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Overall-Image-Assignment-7-1-scaled-e1648305843625-1536x1437.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Overall-Image-Assignment-7-1-scaled-e1648305843625-1200x1123.jpg 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<h2>Code:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/*\r\n * Assignment 7: Sound with Meaning\r\n * Judson Kyle\r\n * judsonk\r\n * \r\n * Description: This sketch plays a sound corresponding to the users mood at the\r\n *              time. Depending on the button pressed, a sound corresponding to\r\n *              one of three emotions will play. These emotions are intense\/stressed,\r\n *              happy\/upbeat, and peaceful\/relaxed corresponding to buttons 0, 1,\r\n *              and 2 respectively. Each sound will only play once through to the\r\n *              end and not repeat after that.\r\n *\/\r\n\r\n#include &lt;Audio.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;SPI.h&gt;\r\n#include &lt;SD.h&gt;\r\n#include &lt;SerialFlash.h&gt;\r\n\r\nAudioPlaySdWav           playWav1;\r\nAudioMixer4              mixer1;         \/\/xy=647,408\r\nAudioOutputMQS           mqs1;           \/\/xy=625,279\r\nAudioConnection          patchCord1(playWav1, 0, mqs1, 0);\r\nAudioConnection          patchCord2(playWav1, 1, mqs1, 1);\r\n\r\n#define SDCARD_CS_PIN    BUILTIN_SDCARD\r\n#define SDCARD_MOSI_PIN  11  \/\/ not actually used\r\n#define SDCARD_SCK_PIN   13  \/\/ not actually used\r\n\r\n#define SWITCH0   33\r\n#define SWITCH1   34\r\n#define SWITCH2   35\r\n#define SWITCH3   37\r\n#define SWITCH4   38\r\n#define SWITCH5   39\r\n\r\n#define BUTTON0   16\r\n#define BUTTON1   17\r\n#define BUTTON2   18\r\n\r\nunsigned long currTime = 0;\r\nunsigned long debounceTime = 0;\r\nvolatile unsigned long startTime = 0;\r\n\r\nvolatile bool DEBOUNCE = false;\r\n\r\nint numButtons = 3;\r\n\r\nvolatile int state = 0;\r\n\r\nconst char* currFileName = \"Shark Attack Shortened.WAV\";\r\n\r\nvoid setup(void)\r\n{\r\n  \/\/ Wait for at least 3 seconds for the USB serial connection\r\n  Serial.begin (9600);\r\n\r\n  AudioMemory(8);\r\n\r\n  pinMode(SWITCH0, INPUT);\r\n  pinMode(SWITCH1, INPUT);\r\n  pinMode(SWITCH2, INPUT);\r\n  pinMode(SWITCH3, INPUT);\r\n  pinMode(SWITCH4, INPUT);\r\n  pinMode(SWITCH5, INPUT);\r\n\r\n  attachInterrupt(digitalPinToInterrupt(BUTTON0), button0Pressed, CHANGE);\r\n  attachInterrupt(digitalPinToInterrupt(BUTTON1), button1Pressed, CHANGE);\r\n  attachInterrupt(digitalPinToInterrupt(BUTTON2), button2Pressed, CHANGE);\r\n\r\n  SPI.setMOSI(SDCARD_MOSI_PIN);\r\n  SPI.setSCK(SDCARD_SCK_PIN);\r\n  if (!(SD.begin(SDCARD_CS_PIN))) {\r\n    \/\/ stop here, but print a message repetitively\r\n    while (1) {\r\n      Serial.println(\"Unable to access the SD card\");\r\n      delay(500);\r\n    }\r\n  }\r\n\r\n}\r\n\r\nvoid loop (void)\r\n{\r\n  currTime = millis();\r\n  static int prevState = 0;\r\n\r\n  if (prevState != state) {\r\n    if (playWav1.isPlaying()) {\r\n      playWav1.stop();\r\n    }\r\n    switch (state) {\r\n      case 0: \/\/Play intense sound\r\n        currFileName = \"Shark Attack Shortened.WAV\";\r\n        playWav1.play(currFileName);\r\n        printPlayState(currFileName);\r\n        delay(5);\r\n        break;\r\n      case 1: \/\/Play fun\/upbeat sound\r\n        currFileName = \"African_fun_long.WAV\";\r\n        playWav1.play(currFileName);\r\n        printPlayState(currFileName);\r\n        delay(5);\r\n        break;\r\n      case 2: \/\/Play peaceful sound\r\n        currFileName = \"With-You-in-My-Arms-SSJ011001.WAV\";\r\n        playWav1.play(currFileName);\r\n        printPlayState(currFileName);\r\n        delay(5);\r\n        break;\r\n    }\r\n  }\r\n  prevState = state;\r\n  \r\n  \/\/Update debounce state\r\n  DEBOUNCE = abs(currTime - startTime) &lt; debounceTime;\r\n}\r\n\r\n\/\/Button 0 interrupt function\r\nvoid button0Pressed() {\r\n  if ((digitalRead(BUTTON0) &lt; 1) &amp;&amp; !DEBOUNCE) {\r\n    state = 0;\r\n    startTime = currTime;\r\n    DEBOUNCE = true;\r\n  }\r\n}\r\n\r\n\/\/Button 1 interrupt function\r\nvoid button1Pressed() {\r\n  if ((digitalRead(BUTTON1) &lt; 1) &amp;&amp; !DEBOUNCE) {\r\n    state = 1;\r\n    startTime = currTime;\r\n    DEBOUNCE = true;\r\n  }\r\n}\r\n\r\n\/\/Button 2 interrupt function\r\nvoid button2Pressed() {\r\n  if ((digitalRead(BUTTON2) &lt; 1) &amp;&amp; !DEBOUNCE) {\r\n    state = 2;\r\n    startTime = currTime;\r\n    DEBOUNCE = true;\r\n  }\r\n}\r\n\r\n\/\/Print out the current cong being played or return an error message if the song isn't being played\r\nvoid printPlayState(const char* fileName) {\r\n  if (!playWav1.isPlaying()) {\r\n    Serial.print(\"Error playing: \");\r\n    Serial.println(fileName);\r\n    delay(5);\r\n  }\r\n  else {\r\n    Serial.print(\"Playing: \");\r\n    Serial.println(fileName);\r\n    delay(5);\r\n  }\r\n}<\/pre>\n<h2>Electrical Schematic:<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-2431\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Assignment_7_Electrical_Schematic_schem.png\" alt=\"\" width=\"1761\" height=\"1008\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Assignment_7_Electrical_Schematic_schem.png 1761w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Assignment_7_Electrical_Schematic_schem-300x172.png 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Assignment_7_Electrical_Schematic_schem-1024x586.png 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Assignment_7_Electrical_Schematic_schem-768x440.png 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Assignment_7_Electrical_Schematic_schem-1536x879.png 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/03\/Assignment_7_Electrical_Schematic_schem-1200x687.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description: This project was meant to convey emotions through sound by playing a song corresponding to the user&#8217;s emotions when a button is pressed. Currently there are only 3 buttons for 3 different sounds\/songs but the idea is to be able to hook up more and more as songs stick out as conveying your emotions. &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2411\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Assignment 7: Sound that has meaning&#8221;<\/span><\/a><\/p>\n","protected":false},"author":30,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[17,1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2411"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2411"}],"version-history":[{"count":6,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2411\/revisions"}],"predecessor-version":[{"id":2433,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2411\/revisions\/2433"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}