~
Dependencies: 4DGL-uLCD-SE SDFileSystem
main.cpp
- Committer:
- fkhan39
- Date:
- 2016-09-26
- Revision:
- 8:964e12b5b51e
- Parent:
- 7:1a21d8290cf1
- Child:
- 9:63c3c734a620
File content as of revision 8:964e12b5b51e:
#include "mbed.h" #include "uLCD_4DGL.h" #include "LSM9DS1.h" #include "math.h" //#include "SongPlayer.h" #include <fstream> #include <string> #include "SDFileSystem.h" // 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(); if (!imu.begin()) { 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.readAccel(); imu.readMag(); imu.readGyro(); */ //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.ax, imu.ay, imu.az); //lcd.printf("mag: %d %d %d\n\n\r", imu.mx, imu.my, imu.mz); /* 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); } */ // serial com, print statements sent to lcd now /* part 1 AnalogOut aout(p18); AnalogIn ain(p15); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); */ /* part 8 BusOut myleds(LED1,LED2,LED3,LED4); class microphone { public : microphone(PinName pin); float read(); operator float (); private : AnalogIn _pin; }; microphone::microphone (PinName pin): _pin(pin) { } float microphone::read() { return _pin.read(); } inline microphone::operator float () { return _pin.read(); } microphone mymicrophone(p16); */ /* part 1 const double pi = 3.141592653589793238462; const double amplitude = 1.0f; const double offset = 65535/2; // 0xFFFF/2 double rads = 0.0; uint16_t sample = 0; */ // while(1) { // // /* part 1 // // // analog out // for (int i = 0; i < 720; i++) { // rads = (pi * i) / 180.0f; // sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); // aout.write_u16(sample); // } // // // analog in // led1 = (ain > 0.2f) ? 1 : 0; // led2 = (ain > 0.4f) ? 1 : 0; // led3 = (ain > 0.6f) ? 1 : 0; // led4 = (ain > 0.8f) ? 1 : 0; // wait(.01); // */ // // /* part 8 // //read in, subtract 0.67 DC bias, take absolute value, and scale up .1Vpp to 15 for builtin LED display // myleds = int(abs((mymicrophone - (0.67/3.3)))*500.0); // //Use an 8kHz audio sample rate (phone quality audio); // wait(1.0/8000.0); // */ // }