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 mbed-rtos SDFileSystem11
Diff: main.cpp
- Revision:
- 1:ddbed1542633
- Parent:
- 0:6cc2c1f459f1
- Child:
- 2:39d41fd0f52b
diff -r 6cc2c1f459f1 -r ddbed1542633 main.cpp --- a/main.cpp Sun Apr 25 20:02:35 2021 +0000 +++ b/main.cpp Mon Apr 26 21:13:10 2021 +0000 @@ -1,13 +1,27 @@ #include "mbed.h" #include "rtos.h" #include "notes.h" +#include "SDFileSystem.h" +#include <string> +#include <sstream> +#include <iostream> +#include <cstdlib> + Thread motor; - +SDFileSystem sd(p5, p6, p7, p8, "sd"); Serial pc(USBTX, USBRX); // tx, rx -/*void playNote(PwmOut motor, float note){ - motor.period(1/note); - motor.write(.5f); - }*/ +class Note { +public: + int midiNote; + float start; + float stop; + Note(int midi, float sta, float sto) { + start = sta; + stop = sto; + midiNote = midi; + } + }; + class Flipper { @@ -29,6 +43,65 @@ Ticker t1; int main() { + pc.baud(115200); + const char * d; + std::string str = "123.4567"; + d = str.c_str(); + // convert string to float + float num_float = std::atof(d); + + // convert string to double + pc.printf("%f\n", num_float-1.0); + int temp = 0; + + pc.printf("Hello World!"); + string output = ""; + + FILE *fpn = fopen("/sd/notesmatrix.txt", "r"); + FILE *fpstart = fopen("/sd/notesstart.txt", "r"); + FILE *fpfinish = fopen("/sd/notesfinish.txt","r"); + unsigned char c; + pc.printf("I'm here\n"); + + while (!feof(fpn)){ // while not end of file + c = fgetc(fpn); // get a character/byte from the file + if(c == ','){ + stringstream degree(output); + degree >> temp; + pc.printf("%d\n", temp-1); + output = ""; + } else { + output += c; + } + } + output = ""; + while(!feof(fpstart)){ + c = fgetc(fpstart); + if(c == ','){ + d = output.c_str(); + num_float = std::atof(d); + pc.printf("%f\n", num_float); + output = ""; + } else { + output+= c; + } + + } + output = ""; + while(!feof(fpfinish)){ + c = fgetc(fpfinish); + if(c == ','){ + d = output.c_str(); + num_float = std::atof(d); + pc.printf("%f\n", num_float); + output = ""; + } else { + output+= c; + } + + } + + float note1 = 1.0/(NOTE_A4*2); float note2 = 1.0/(NOTE_CS5*2); float note2m = 1.0/(NOTE_C5*2); @@ -36,7 +109,9 @@ t.attach(&f, &Flipper::flip, note1); // the address of the object, member function, and interval t1.attach(&f1, &Flipper::flip, note2); pc.printf("Hello World!\n"); - pc.printf("%f",note1); + pc.printf("%f\n",note1); + Note myNote = Note(1, 1.0, 1.0); + pc.printf("%d", myNote.midiNote); // spin in a main loop. flipper will interrupt it to call flip while(1) { for(int i = 0; i < 10; i++) {