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.
Dependencies: LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile
main.cpp
- Committer:
- linx0576
- Date:
- 2015-12-12
- Revision:
- 2:afdb1aaa7608
- Parent:
- 1:f1f3dfff9107
- Child:
- 3:7edb43f86069
File content as of revision 2:afdb1aaa7608:
#include <math.h>
#include "stdio.h"
#include "mbed.h"
#include "SPI_TFT_ILI9341.h"
#include "string"
#include "Arial12x12.h"
#include "Arial24x23.h"
#include "arm_math.h"
#define num 128
//AnalogIn analogValue(A2);
DigitalIn bt(PC_8);
/** External Input and Output buffer Declarations for FFT Bin Example **/
//static float32_t testInput_f32_10khz[num];
/** Global variables for FFT Bin Example **/
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;
/* Reference index at which max energy of bin ocuurs */
uint32_t refIndex = 213, testIndex = 0;
extern unsigned char p1[]; // the mbed logo
const float32_t a[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
-1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454,
1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430, 2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620,
-2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910, -1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426,
-4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387, 0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287,
0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723, 0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345,
1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834, 0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279,
-0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
};
const float32_t b[num] = { -0.865129623056441, -2.655020678073846, 0.600664612949661, 0.080378093886515, -2.899160484012034, 2.563004262857762, 3.078328403304206, 0.105906778385130,
0.048366940168201, -0.145696461188734, -0.023417155362879, 2.127729174988954, -1.176633086028377, 3.690223557991855, -0.622791766173194, 0.722837373872203,
2.739754205367484, -0.062610410524552, -0.891296810967338, -1.845872258871811, 1.195039415434387, -2.177388969045026, 1.078649103637905, 2.570976050490193,
-1.383551403404574, 2.392141424058873, 2.858002843205065, -3.682433899725536, -0.369328108540868, 0.810791418361879, 3.587016488699641, -0.520776145083723,
0.640249919627884, 1.103122489464969, 2.231779881455556, -1.308035392685241, 0.424070304330106, -0.200383932651189, -2.365526783356541, -0.989114757436628,
2.770807688959777, -0.444172737462307, 0.079760979374078, -0.005199118412183, -0.664712668309527, -0.624171857561896, 0.537306979007338, -2.575955675497642,
1.562363235756780, 1.814069369848895, -1.293428583392509, -1.026188449495686, -2.981771815588717, -4.223468103075124, 2.672674782004045, -0.856096801117735,
0.048517345512563, -0.026860721136222, 0.392932277758187, -1.331740855093099, -1.894292129477081, -1.425006468460681, -2.721772427617057, -1.616831100216806,
3.551177651488947, -0.069685667896087, -3.134634907409102, -0.263627598944639, -1.650469945991350, -2.203580339374399, -0.872203246123242, 1.230782812607287,
0.257288860093291, 1.989083106173137, -1.985638729453261, -1.416185105842892, -1.131097688325772, -2.245130805416057, -1.938873996219074, 2.043608361562645,
-3.488146646451150, 1.323468578888120, -0.099771155430726, 1.561168082500454, 1.025026795103179, 0.928841900171200, 2.930499509864950, 2.013349089766430,
2.381676148486737, -3.081062307950236, -0.389579115537544, 0.181540149166620, -2.601953341353208, 0.333435137783218, -2.812945856162965, 2.649109640172910,
-1.003963025744654, 1.552460768755035, 0.088641345335247, -2.519951327113426, -4.341348988610527, 0.557772429359965, -1.671267412948494, 0.733951350960387,
0.409263788034864, 3.566033071952806, 1.882565173848352, -1.106017073793287, 0.154456720778718, -2.513205795512153, 0.310978660939421, 0.579706500111723,
0.000086383683251, -1.311866980897721, 1.840007477574986, -3.253005768451345, 1.462584328739432, 1.610103610851738, 0.761914676858907, 0.974541361089834,
0.686845845885983, 1.849153122025191, 0.787800410401453, -1.187438909666279, -0.754937911044720, 0.084373858395232, -2.600269011710521, -0.962982842142644,
};
float32_t a1, b1;
float32_t subOutput, SquareOutput;
//SPI_TFT_ILI9341 TFT(D11, D12, D13, D10, D8, D9, "TFT"); // mosi, miso, sclk, cs, reset, dc
SPI_TFT_ILI9341 TFT(PC_3, PC_2, PB_10, PB_12, PA_8, PA_11, "TFT"); // mosi, miso, sclk, cs, reset, dc
int main()
{
// arm_cfft_radix2_instance_f32 S;
int stage=0;
int pu, pd, pl, pr, ps;
TFT.claim(stdout); // send stdout to the TFT display
TFT.claim(stderr); // send stderr to the TFT display
TFT.set_orientation(2); // comment out = "||" include = "="
TFT.background(Black); // set background to black
TFT.foreground(White); // set chars to white
TFT.cls(); // clear the screen
while(1)
{ TFT.cls();
TFT.background(Black);
if (stage==0) //menu
{ int menu=0;
TFT.cls();
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(20,60);
printf("Configuration");
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(20,110);
TFT.printf(" Waveform");
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(20,160);
TFT.printf(" Log");
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(20,260);
printf(" Return");
if (menu==0) //Configuration
{ pu=0; pd=0; pl=0; pr=0; ps=0;
TFT.rect(15,55,220,85,GreenYellow);
TFT.rect(15,105,220,135,Black);
ps=1;
if (pd==1) {wait(1); menu=1;}
if (ps==1) {wait(1); stage=1;}
}
if (menu==1) //waveform
{ pu=0; pd=0; pl=0; pr=0; ps=0;
TFT.rect(15,55,220,85,Black);
TFT.rect(15,105,220,135,GreenYellow);
TFT.rect(15,155,220,185,Black);
pd=1;
if (pu==1) {wait(1); menu=0;}
if (pd==1) {wait(1); menu=2;}
if (ps==1) {wait(1); stage=2;}
}
if (menu==2) //log
{ pu=0; pd=0; pl=0; pr=0; ps=0;
TFT.rect(15,105,220,135,Black);
TFT.rect(15,155,220,185,GreenYellow);
TFT.rect(15,255,220,285,Black);
ps=1;
if (pu==1) {wait(1); menu=1;}
if (pd==1) {wait(1); menu=3;}
if (ps==1) {wait(1); stage=3;}
}
if (menu==3) //return
{ pu=0; pd=0; pl=0; pr=0; ps=0;
TFT.rect(15,155,220,185,Black);
TFT.rect(15,255,220,285,GreenYellow);
if (pu==1) {wait(1); menu=0;}
if (ps==1) {wait(1); stage=3;}
}
}
if (stage==1) //Configuration
{ TFT.cls();
int i, j;
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(20,60);
printf("SET PERIOD");
TFT.rect(15,55, 220,85,Red);
TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(40,270);
printf("Set");
TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(165,270);
printf("Return");
pu=0; pd=0; pl=1; pr=0; ps=0;
i=3; j=38;
while (ps==0)
{ TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(20,130);
TFT.printf(" %i %i", i-1, j-1);
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(20,150);
TFT.printf(" %i Hr %i Min", i, j);
TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(20,180);
TFT.printf(" %i %i", i+1, j+1);
pu=0; pd=0; pl=1; pr=0; ps=0;
if (pl==1)
{ TFT.rect(20,145, 58,175,Yellow);
TFT.rect(120,145,158,175,Blue);
pu=1;
if (i>05) i=0;
if (pu==1) {wait(1); i=i+1; }
if (pd==1) {wait(1); i=i-1; }
}
pu=0; pd=0; pl=0; pr=1; ps=0;
if (pr==1)
{ TFT.rect(20,145, 58,175,Blue);
TFT.rect(120,145,158,175,Yellow);
pu=1;
if (j>60) j=0;
if (pu==1) {wait(1); j=j+1; }
if (pd==1) {wait(1); j=j-1; }
}
// ps=1;
}
pu=0; pd=0; pl=1; pr=0; ps=0;
while (ps==0)
{ if (pl==1)
{ TFT.rect(15,265,85,285,GreenYellow);
TFT.rect(150,265,220,285,Black);
wait(1);
}
pr=1;
if (pr==1)
{ TFT.rect(15,265,85,285,Black);
TFT.rect(150,265,220,285,GreenYellow);
wait(1);
}
ps=1;
if (ps==1) {wait(1); stage=0;}
}
}
if (stage==2) //waveform
{ TFT.cls();
pu=0; pd=0; pl=0; pr=0; ps=0;
int abc, x2, y2;
int x1 = 0;
int y1 = 100;
float32_t sum=0;
float32_t k=0;
for(abc=0; abc<num; abc++)
{ a1 = a[abc];
b1 = b[abc];
arm_sub_f32(&a1, &b1, &subOutput, 1);
arm_mult_f32(&subOutput, &subOutput, &SquareOutput, 1);
sum = sum+SquareOutput;
x2 = abc*2;
y2 = 80+a1*10;
TFT.line(x1,y1,x2,y2,Green);
x1 = x2;
y1 = y2;
}
k = sum / num;
TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(10,180);
TFT.printf("sum: %f", sum);
TFT.locate(10,190);
TFT.printf("num: %i", num);
TFT.locate(10,210);
TFT.printf("Mean Square Error: ");
TFT.locate(10,220);
TFT.printf(" %f", k);
TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(165,270);
printf("Return");
TFT.rect(150,265,220,285,GreenYellow);
ps=1;
if (ps==1) {wait(1); stage=0;}
}
if (stage==3) //log
{ TFT.cls();
pu=0; pd=0; pl=0; pr=0; ps=0;
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(20,60);
printf("Team Riedel");
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(30,110);
TFT.printf("We are");
TFT.set_font((unsigned char*) Arial24x23);
TFT.locate(40,160);
TFT.printf("awesome!");
TFT.set_font((unsigned char*) Arial12x12);
TFT.locate(165,270);
printf("Return");
TFT.rect(150,265,220,285,GreenYellow);
ps=1;
if (ps==1) {wait(1); stage=0;}
}
}
}