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.
main.cpp
00001 /* 00002 * This is my code. It takes 16 samples of the analog in pins and writes the values back to the serial port. 00003 * Nathan Lasseter 2010 00004 */ 00005 00006 #include "mbed.h" 00007 #include "TextLCD.h" 00008 00009 extern void fft(float inarr[16], float outarr[16]); //look for fft at link not compile time 00010 00011 //Serial pc(USBTX,USBRX); ///dev/ttyACM0 is locked on university pc's 00012 Serial pc(p9,p10); //So I use /dev/ttyS0 instead 00013 BusOut bargraph(p21,p22,p23,p24,p25,p26,p27,p28,p29,p30); //Dot matrix bargraphs horizontal bus 00014 BusOut graphs(p11,p12,p13,p14,p15,p16,p17,p18); //Dot matrix bargraphs vertical bus 00015 AnalogIn left(p19); //Left channel input 00016 AnalogIn right(p20); //Right channel input 00017 00018 void outputmatrix(float avg, int which) { //This is the simple dot matrix driver. 00019 switch (which) { //Select a bargraph 00020 case 8: graphs = 0xFF; //8: off 00021 case 0: graphs = 0xFE; //0-7 are right to left. They turn on a bargraph by going low. 00022 case 1: graphs = 0xFC; 00023 case 2: graphs = 0xF8; 00024 case 3: graphs = 0xF0; 00025 case 4: graphs = 0xE0; 00026 case 5: graphs = 0xC0; 00027 case 6: graphs = 0x80; 00028 case 7: graphs = 0x00; 00029 } 00030 if (avg > 0.9) { bargraph=0x3FF; return; } //Same principle, but set a value on the graph. 00031 if (avg > 0.8) { bargraph=0x1FF; return; } 00032 if (avg > 0.7) { bargraph=0x0FF; return; } 00033 if (avg > 0.6) { bargraph=0x07F; return; } 00034 if (avg > 0.5) { bargraph=0x03F; return; } 00035 if (avg > 0.4) { bargraph=0x01F; return; } 00036 if (avg > 0.3) { bargraph=0x00F; return; } 00037 if (avg > 0.2) { bargraph=0x007; return; } 00038 if (avg > 0.1) { bargraph=0x003; return; } 00039 if (avg > 0.0) { bargraph=0x001; return; } 00040 bargraph=0x000; //Default to all off 00041 } 00042 00043 int main() { //Main code 00044 while(1) { 00045 int i; 00046 /* float leftin[16], leftout[16]; //While technically it can support 16 bands over each of 2 channels... 00047 float rightin[16], rightout[16]; 00048 for(i=0;i<16;i++) leftin[i] = left; 00049 for(i=0;i<16;i++) rightin[i] = right; 00050 fft(leftin, leftout); 00051 fft(rightin, rightout); */ 00052 float in[16], out[16], avg[8]; //I only use 8 on one channel 00053 for(i=0;i<16;i++) in[i] = (left + right) / 2; //So I average the two 00054 fft(in, out); 00055 for(i=0;i<8;i++) avg[i] = (out[2*i] + out[(2*i)+1]) / 2; //And then average pairs of bands 00056 /* pc.printf("%f %f %f %f %f %f %f %f\t%f %f %f %f %f %f %f %f\n", 00057 leftout[0], leftout[1], leftout[2], leftout[3], 00058 leftout[4], leftout[5], leftout[6], leftout[7], 00059 leftout[8], leftout[9], leftout[10], leftout[11], 00060 leftout[12], leftout[13], leftout[14], leftout[15]); 00061 pc.printf("%f %f %f %f %f %f %f %f\t%f %f %f %f %f %f %f %f\n\n", 00062 rightout[0], rightout[1], rightout[2], rightout[3], 00063 rightout[4], rightout[5], rightout[6], rightout[7], 00064 rightout[8], rightout[9], rightout[10], rightout[11], 00065 rightout[12], rightout[13], rightout[14], rightout[15]); */ 00066 pc.printf("%f %f %f %f\t%f %f %f %f\r\n", //Then print the values to the uart 00067 avg[0], avg[1], avg[2], avg[3], 00068 avg[4], avg[5], avg[6], avg[7]); 00069 for(i=0;i<8;i++) outputmatrix(avg[i], i); //And display on the bargrpahs 00070 } 00071 }
Generated on Tue Jul 19 2022 20:21:25 by
1.7.2