~
Dependencies: 4DGL-uLCD-SE SDFileSystem
Diff: main.cpp
- Revision:
- 7:1a21d8290cf1
- Parent:
- 6:708e878d4374
- Child:
- 8:964e12b5b51e
--- a/main.cpp Mon Sep 26 15:17:41 2016 +0000 +++ b/main.cpp Mon Sep 26 17:26:28 2016 +0000 @@ -1,11 +1,52 @@ #include "mbed.h" #include "uLCD_4DGL.h" #include "LSM9DS1.h" +#include "math.h" +//#include "SongPlayer.h" +#include <fstream> +#include <string> +#include "SDFileSystem.h" -DigitalOut myled(LED1); + +// serial Serial pc(USBTX, USBRX); + +// part 4 + uLCD_4DGL lcd(p13,p14,p12); + +// part 9A +SDFileSystem sd(p5, p6, p7, p8, "sd"); +/* +// part 9B +float note[16]= {329.628,329.628,329.628,349.228,391.995,391.995,391.995,349.228, + 329.628,349.228,391.995,349.228,329.628,293.665,329.628,349.228 + }; +float duration[16]= {0.48,0.12,0.48,0.12,0.48,0.12,0.12,0.12, + 0.12,0.12,0.12,0.12,0.48,0.12,1.68,0.12 + }; +*/ + + int main() { + //sd + 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, "Hello SD file World!"); + fclose(fp); + + std::ifstream file("/sd/mydir/sdtest.txt"); + string str; + + while (std::getline(file, str)) + { + const char * c = str.c_str(); + pc.printf(c); + } + //imu9DS1 imu(p9, p10, 0x6B, 0x1E); LSM9DS1 imu(p9, p10, 0xD6, 0x3C); imu.begin(); @@ -13,7 +54,21 @@ lcd.printf("Failed to communicate with imu9DS1.\n"); } imu.calibrate(); + + + // part 9, speaker + /* +// setup instance of new SongPlayer class, mySpeaker using pin 26 +// the pin must be a PWM output pin + SongPlayer mySpeaker(p26); +// Start song and return once playing starts + mySpeaker.PlaySong(note,duration); + double theta; + */ + int ax, ay; while(1) { + // loops forever while song continues to play to end using interrupts + imu.calibrate(); imu.readAccel(); imu.readMag(); imu.readGyro(); @@ -21,11 +76,23 @@ //lcd.printf("%d %d %d %d %d %d %d %d %d\n\r", imu.calcGyro(imu.gx), imu.calcGyro(imu.gy), imu.calcGyro(imu.gz), imu.ax, imu.ay, imu.az, imu.mx, imu.my, imu.mz); //lcd.printf("%d %d %d\n\r", imu.calcGyro(imu.gx), imu.calcGyro(imu.gy), imu.calcGyro(imu.gz)); //lcd.printf("gyro: %d %d %d\n\r", imu.gx, imu.gy, imu.gz); - lcd.printf("accel: %d %d %d\n\r", imu.calcAccel(imu.ax), imu.calcAccel(imu.ay), imu.calcAccel(imu.az)); + //lcd.printf("accel: %d %d %d\n\r", imu.ax, imu.ay, imu.az); //lcd.printf("mag: %d %d %d\n\n\r", imu.mx, imu.my, imu.mz); - lcd.circle(64, 64, 10, 0xD3D3D3); - lcd.filled_circle(64, 64, 8, WHITE); - wait(.05); + if (push) { + lcd.filled_circle(64 + ax / 250, 64 + ay/ 250 , 8, BLACK); + ax = imu.ax, ay = imu.ay; + lcd.filled_circle(64 + ax / 250, 64 + ay/ 250 , 8, WHITE); + lcd.circle(64, 64, 10, WHITE); + } else { + // compass, part 4 extra credit + + lcd.line(64,64,64+60*cos(theta), 64+60*sin(theta), BLACK); + theta = atan2((double)imu.mx, (double)imu.my); + lcd.line(64,64,64+60*cos(theta), 64+60*sin(theta), GREEN); + lcd.locate(0,1); + lcd.printf("%f",180 * theta / 3.14159); + } + } }