Nathaniel Garcia
/
SquareRoot_Calculator_KL46Z
Gets input from slider and returns the square root of that number
main.cpp
- Committer:
- Raiden817
- Date:
- 2016-10-06
- Revision:
- 0:be53fac41c7a
- Child:
- 1:81905675b73e
File content as of revision 0:be53fac41c7a:
#include "mbed.h" #include <math.h> #include "TSISensor.h" #include "SLCD.h" #define LEDON false #define FEDOFF true #define NUMBUTS 2 #define LBUT PTC12 #define RBUT PTC3 #define ARGUENTSTATE 0 #define ARGUMENTANSWER 1 #define TSILIMIT 0.01 #define PRINTDELTA 0.01 #define LCDCHARLEN 10 #define DATAINTERVAL 0.1 #define BUTTONTIME 0.1 #define PROGNAME "kSquareRoot_Calculator_KL46Z\n\r" SLCD slcd; //define LCD display Serial pc(USBTX, USBRX); Timer dataTimer; Timer buttonTimer; DigitalIn buttons[NUMBUTS] = {RBUT, LBUT}; float tsiData; int displayState; void initialize_global_vars(){ pc.printf(PROGNAME); buttonTimer.start(); buttonTimer.reset(); dataTimer.start(); dataTimer.reset(); } void LCDMess(char *lMess){ slcd.Home(); slcd.clear(); slcd.printf(lMess); } int squareRoot(int val) { double sqr = 0; return sqr; } int main(void) { int i; float lastTouch = 0.0; char lcdData[LCDCHARLEN]; PwmOut gled(LED_GREEN); PwmOut rled(LED_RED); pc.printf(PROGNAME); TSISensor tsi; float tempTSI; initialize_global_vars(); while (true) { if (buttonTimer > BUTTONTIME) { for (i = 0; i < NUMBUTS; i++) { if(!buttons[i]) { displayState = i; } } //Get slider value if (displayState == 0) { rled = 1.0; gled = 0.0; if (dataTimer.read() > DATAINTERVAL) { dataTimer.reset(); tempTSI = tsi.readPercentage(); tempTSI = tempTSI * 100; if (tempTSI > TSILIMIT) { tsiData = tempTSI; if (tempTSI > TSILIMIT) { tsiData = tempTSI; if (fabs(tsiData - lastTouch) > PRINTDELTA) { pc.printf("Position %0.4f\n\r", tsiData); } } lastTouch = tsiData; } } } //Perform SquareRoot else { rled = 0.0; gled = 1.0; } buttonTimer.reset(); sprintf(lcdData,"%0.4f",tsiData); LCDMess(lcdData); } } }