~
Dependencies: 4DGL-uLCD-SE SDFileSystem
main.cpp
- Committer:
- kswanson31
- Date:
- 2016-09-26
- Revision:
- 13:c14dc22c38ba
- Parent:
- 12:a2908fdf3b66
- Child:
- 14:2c2395937c57
File content as of revision 13:c14dc22c38ba:
#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 1 AnalogOut aout(p18); AnalogIn ain(p15); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); */ /* PART 3 Serial pc(p13, p14); // TX, RX */ /* 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 4 uLCD_4DGL lcd(p13,p14,p12); int ax, ay; */ /* PART 6 */ DigitalOut myled(LED1); DigitalOut Ctrl(p25); // comment this out for digital, comment below //PwmOut Ctrl(p25); /*PART 9, SD CARD SDFileSystem sd(p5, p6, p7, p8, "sd"); */ /* PART 9B, SOUND 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() { /* 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; */ /* PART 4, BUBBLE, PART 3 LSM9DS1 imu(p9, p10, 0xD6, 0x3C); imu.begin(); if (!imu.begin()) { pc.printf("Failed to communicate with imu9DS1.\n"); } imu.calibrate(); */ /* PART 9, SD CARD 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); } */ /* 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; */ 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); */ /* PART 3 imu.readAccel(); imu.readMag(); imu.readGyro(); pc.printf("gyro: %d %d %d\n\r", imu.gx, imu.gy, imu.gz); pc.printf("accel: %d %d %d\n\r", imu.ax, imu.ay, imu.az); pc.printf("mag: %d %d %d\n\n\r", imu.mx, imu.my, imu.mz); */ /* PART 4, BUBBLE/COMPASS imu.readAccel(); imu.readMag(); imu.readGyro(); 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); // 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); */ /* PART 6 */ // using DigitalOut Ctrl = 1; myled = 1; wait(.2); Ctrl = 0; myled = 0; wait(.2); // using PwmOut /* myled = 1; for (int i = 0; i < 5; i++) { Ctrl = i*0.2f; wait(.1); myled = 0; wait(.1); } */ } } /* , / \ { } p ! ; : ; | : | | : | l ; l l ; l I ; I I ; I I ; I I ; I d | b H | H H | H H I H ,;, H I H ,;, ;H@H; ;_H_;, ;H@H; `\Y/d_,;|4H@HK|;,_b\Y/' '\;MMMMM$@@@$MMMMM;/' "~~~*;!8@8!;*~~~" ;888; ;888; ;888; ;888; d8@8b O8@8O T808T `~` */