Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed SDFileSystem
Diff: main.cpp
- Revision:
- 5:e297f321fa20
- Parent:
- 4:d414aee7ce9d
- Child:
- 6:7f0a090b12e2
--- a/main.cpp Fri Apr 26 07:28:26 2019 +0000
+++ b/main.cpp Fri Apr 26 15:30:05 2019 +0000
@@ -1,7 +1,19 @@
// ESE350 Final Project: Drue
#include "mbed.h"
+#include "wave_player.h"
+#include "SDFileSystem.h"
+//#include "SDBlockDevice.h"
+
+//#include "sdCard.cpp"
+
// Pin setup ////////////////////////////////////////////
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+Timer timer;
+Serial pc(USBTX, USBRX);
+AnalogOut DACout(p18); //set up speaker
+wave_player waver(&DACout); //set up wave player library
+
// Button Inputs
DigitalIn butC(p14);
DigitalIn butD(p15);
@@ -62,6 +74,10 @@
butMode.mode(PullUp);
}
+void speakerSetup(){
+
+}
+
void pressKey() {
if (butC == 0 || butD == 0 || butE == 0 || butF == 0 || butG == 0
|| butA == 0 || butB == 0 || butCh == 0) {
@@ -99,7 +115,7 @@
// this if statement initializes first note sound
if (!notePressed) {
if (butC == 0) {
- speaker.period(1.0/523.25);
+ speaker.period(1.0/523.25);
prevNote = 0;
} else if (butD == 0) {
speaker.period(1.0/587.33);
@@ -209,10 +225,37 @@
i2cLED.write(addr, cmd, 1);
}
+void testSd(){
+ pc.printf("Kevin sucks\n");
+ mkdir("/sd/mydir", 0777);
+ FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
+ if(fp == NULL) {
+ error("Could not open file for write\n");
+ }
+ fprintf(fp, "If you see this you owe Mirko a cookie hah");
+ fclose(fp);
+
+ pc.printf("Mirko wins\n");
+}
+
+void testSpeaker(){
+
+ FILE *wave_file;
+ wave_file = fopen("/sd/notes/C4.wav","r"); //opens the music file
+ waver.play(wave_file); //plays the music file
+ fclose(wave_file);
+}
+
int main() {
+ pc.baud (115200);
variableInit();
buttonSetup();
-
+ speakerSetup();
+ wait(0.5);
+ testSd();
+ testSpeaker();
+ // testSd();
+
while(1) {
lightLED(prevNote);
