-
-
Save cnc4less/96ca893a268361e6c39f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
#include "SLCD.h" | |
#include "MAG3110.h" | |
#include "fft4g.h" | |
#include "aqm1248a_lcd.h" | |
#define NMAX 256 | |
#define NMAXSQRT 32 | |
#define MAX(x,y) ((x) > (y) ? (x) : (y)) | |
MAG3110 mag(PTE25, PTE24); | |
SLCD slcd; | |
aqm1248a_lcd lcd; | |
Ticker reader; | |
bool modeFilling = true; | |
int nFilled = 0; | |
double magBuffer[NMAX+1]; | |
void readerFunction() { | |
if (modeFilling) { | |
float x; | |
mag.getX(&x); | |
if (nFilled < NMAX) { | |
magBuffer[nFilled++] = x; | |
if (nFilled >= NMAX) { | |
modeFilling = false; | |
} | |
} | |
} | |
} | |
void putdata(int n, double *a) | |
{ | |
int j; | |
double pi2 = 3.14159265*2 / n; | |
for (j = 0; j <n; j++) { | |
a[j] = sin(j*pi2*10)*10 + sin(j*pi2*15)*5 + sin(j*pi2*20)*10; | |
} | |
} | |
int main() | |
{ | |
char buf[80]; | |
int n, ip[NMAXSQRT + 2]; | |
double w[NMAX * 5 / 4]; | |
ip[0] = 0; | |
n = NMAX; | |
int cnt = 0; | |
lcd.setmode(NORMAL); | |
lcd.set_contrast(25); | |
mag.enable(); | |
wait(0.1); | |
reader.attach(&readerFunction, 0.0333333); | |
while (1) { | |
while(modeFilling == true) wait(0.1); | |
rdft(n, 1, magBuffer, ip, w); | |
int n2 = n/2; | |
int height = lcd.height(); | |
int width = lcd.width(); | |
double max = 0; | |
for (int i = 0; i < n2; i++) { | |
int i2 = i*2; | |
magBuffer[i] = magBuffer[i2]*magBuffer[i2] + magBuffer[i2+1]*magBuffer[i2+1]; | |
if (i > 0 && magBuffer[i] > max) max = magBuffer[i]; | |
} | |
lcd.cls(); | |
lcd.locate(0,0); | |
lcd.printf("%lf", max); | |
max = height / max; | |
for (int i = 1; i < n2; i++) { | |
lcd.line(i, height-1, i, height-1-max*magBuffer[i], 1); | |
} | |
sprintf(buf, "%4d", cnt++); | |
slcd.printf(buf); | |
if (cnt > 9999) cnt = 0; | |
nFilled = 0; | |
modeFilling = true; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment