this hurts

Dependencies:   FFT

Committer:
annieluo2
Date:
Wed Dec 02 18:02:03 2020 +0000
Revision:
0:d6c9b09b4042
Child:
1:5dd6801bb0d6
boo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
annieluo2 0:d6c9b09b4042 1 #include "mbed.h"
annieluo2 0:d6c9b09b4042 2 #include "SDFileSystem.h"
annieluo2 0:d6c9b09b4042 3 #include "wave_player.h"
annieluo2 0:d6c9b09b4042 4 #include "Adafruit_LEDBackpack.h"
annieluo2 0:d6c9b09b4042 5 #include "Adafruit_GFX.h"
annieluo2 0:d6c9b09b4042 6 #include "rtos.h"
annieluo2 0:d6c9b09b4042 7 #include "FFT.h"
annieluo2 0:d6c9b09b4042 8
annieluo2 0:d6c9b09b4042 9 SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD card
annieluo2 0:d6c9b09b4042 10
annieluo2 0:d6c9b09b4042 11 I2C i2c(p28, p27); // LED display
annieluo2 0:d6c9b09b4042 12 Adafruit_8x8matrix matrix = Adafruit_8x8matrix(&i2c);
annieluo2 0:d6c9b09b4042 13
annieluo2 0:d6c9b09b4042 14 AnalogOut DACout(p18); // speaker
annieluo2 0:d6c9b09b4042 15 wave_player waver(&DACout);
annieluo2 0:d6c9b09b4042 16 Mutex speaker_lock;
annieluo2 0:d6c9b09b4042 17
annieluo2 0:d6c9b09b4042 18 DigitalOut myled(LED1); // mbed LED
annieluo2 0:d6c9b09b4042 19
annieluo2 0:d6c9b09b4042 20 void fft_calc_thread(void const* args) {
annieluo2 0:d6c9b09b4042 21 //something
annieluo2 0:d6c9b09b4042 22 //pull the array off of sd card
annieluo2 0:d6c9b09b4042 23 //vTealfft(arr, 1024);
annieluo2 0:d6c9b09b4042 24 while(1) {
annieluo2 0:d6c9b09b4042 25 myled = 1;
annieluo2 0:d6c9b09b4042 26 wait(0.2);
annieluo2 0:d6c9b09b4042 27 myled = 0;
annieluo2 0:d6c9b09b4042 28 wait(0.2);
annieluo2 0:d6c9b09b4042 29 }
annieluo2 0:d6c9b09b4042 30 }
annieluo2 0:d6c9b09b4042 31
annieluo2 0:d6c9b09b4042 32 void speaker_thread(void const* args)
annieluo2 0:d6c9b09b4042 33 {
annieluo2 0:d6c9b09b4042 34 while(1)
annieluo2 0:d6c9b09b4042 35 {
annieluo2 0:d6c9b09b4042 36 // grab file here and put together string
annieluo2 0:d6c9b09b4042 37 // string song_title = "/sd/" + "" + ".wav";
annieluo2 0:d6c9b09b4042 38
annieluo2 0:d6c9b09b4042 39 FILE *wave_file;
annieluo2 0:d6c9b09b4042 40 wave_file=fopen("/sd/africa-toto.wav","r");
annieluo2 0:d6c9b09b4042 41
annieluo2 0:d6c9b09b4042 42 speaker_lock.lock();
annieluo2 0:d6c9b09b4042 43 waver.play(wave_file);
annieluo2 0:d6c9b09b4042 44 speaker_lock.unlock();
annieluo2 0:d6c9b09b4042 45 fclose(wave_file);
annieluo2 0:d6c9b09b4042 46 Thread::wait(100);
annieluo2 0:d6c9b09b4042 47
annieluo2 0:d6c9b09b4042 48 }
annieluo2 0:d6c9b09b4042 49 }
annieluo2 0:d6c9b09b4042 50
annieluo2 0:d6c9b09b4042 51
annieluo2 0:d6c9b09b4042 52 int main()
annieluo2 0:d6c9b09b4042 53 {
annieluo2 0:d6c9b09b4042 54
annieluo2 0:d6c9b09b4042 55 Thread th1(speaker_thread);
annieluo2 0:d6c9b09b4042 56 Thread th2(fft_calc_thread);
annieluo2 0:d6c9b09b4042 57
annieluo2 0:d6c9b09b4042 58 matrix.begin(0x70);
annieluo2 0:d6c9b09b4042 59 while(1) {
annieluo2 0:d6c9b09b4042 60 for (int i = 0; i < 8; i++) {
annieluo2 0:d6c9b09b4042 61 for (int j = 0; j < 8; j++) {
annieluo2 0:d6c9b09b4042 62 matrix.clear();
annieluo2 0:d6c9b09b4042 63 matrix.drawPixel(i, j, LED_ON);
annieluo2 0:d6c9b09b4042 64 matrix.writeDisplay();
annieluo2 0:d6c9b09b4042 65 wait(.5);
annieluo2 0:d6c9b09b4042 66 }
annieluo2 0:d6c9b09b4042 67 }
annieluo2 0:d6c9b09b4042 68 Thread::wait(100);
annieluo2 0:d6c9b09b4042 69 }
annieluo2 0:d6c9b09b4042 70
annieluo2 0:d6c9b09b4042 71 }