Playing around with accelerometer and magnetometer on mbed KL46Z
Dependencies: MAG3110 MMA8451Q PinDetect mbed TSI
Revision 13:921cb2856808, committed 2014-02-08
- Comitter:
- mohammmo
- Date:
- Sat Feb 08 03:02:23 2014 +0000
- Parent:
- 12:d9d577c25961
- Child:
- 14:1608275a874f
- Commit message:
- Added Analog input
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Feb 07 09:46:25 2014 +0000 +++ b/main.cpp Sat Feb 08 03:02:23 2014 +0000 @@ -18,6 +18,7 @@ Ticker timerMag; Ticker timerLight; Ticker timerTouch; +Ticker timerAin; // Declare pointer variables float xAcc; @@ -28,18 +29,21 @@ int zMag; float xLight; float xTouch; +float xAin; // Sampling rates -float accRate = 0.1; -float magRate = 0.1; +float accRate = 0.1; +float magRate = 0.1; float lightRate = 0.1; float touchRate = 0.1; +float AinRate = 0.1; // Enables -int accEn = 1; -int magEn = 1; +int accEn = 1; +int magEn = 1; int lightEn = 1; int touchEn = 1; +int AinEn = 1; // Receiving Data const int bufferSize = 255; @@ -57,6 +61,8 @@ TSISensor touch; // Declare light sensor pin AnalogIn light(PTE22); +// Declare Analog input pin +AnalogIn Ain(PTB0); // Functions void init(); @@ -67,6 +73,7 @@ void magTime(); void lightTime(); void touchTime(); +void AinTime(); void init() { @@ -76,6 +83,7 @@ timerMag.attach(&magTime, magRate); timerLight.attach(&lightTime, lightRate); timerTouch.attach(&touchTime, touchRate); + timerAin.attach(&AinTime, AinRate); pc.attach(&receiveHandler, Serial::RxIrq); ledred = 0; ledgreen = 0; @@ -173,6 +181,10 @@ timerTouch.detach(); touchEn = 0; break; + case '5': + timerAin.detach(); + AinEn = 0; + break; default: //pc.printf("incorrect input\r\n"); break; @@ -199,6 +211,9 @@ timerTouch.attach(&touchTime, touchRate); touchEn = 1; break; + case '5': + timerAin.attach(&AinTime, AinRate); + AinEn = 1; default: //pc.printf("incorrect input\r\n"); break; @@ -229,6 +244,11 @@ timerTouch.detach(); timerTouch.attach(&touchTime, touchRate); break; + case '5': + AinRate = temp; + timerAin.detach(); + timerAin.attach(&AinTime, AinRate); + break; default: //pc.printf("incorrect input\r\n"); break; @@ -265,3 +285,8 @@ { xTouch = 1 - touch.readPercentage(); } + +void AinTime() +{ + xAin = Ain.read(); +} \ No newline at end of file