motion data on button press
Dependencies: FXAS21002 FXOS8700 Hexi_KW40Z
Fork of Hexi_Buttons_Example by
main.cpp
- Committer:
- cotigac
- Date:
- 2016-09-19
- Revision:
- 1:80e17bcc26e4
- Parent:
- 0:f7ef26f17610
- Child:
- 2:5b025ef2835a
File content as of revision 1:80e17bcc26e4:
#include "mbed.h" #include "Hexi_KW40Z.h" #define LED_ON 0 #define LED_OFF 1 void StartHaptic(void); void StopHaptic(void const *n); DigitalOut redLed(LED1); DigitalOut greenLed(LED2); DigitalOut blueLed(LED3); DigitalOut haptic(PTB9); /* Define timer for haptic feedback */ RtosTimer hapticTimer(StopHaptic, osTimerOnce); /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ KW40Z kw40z_device(PTE24, PTE25); void ButtonUp(void) { StartHaptic(); redLed = LED_ON; greenLed = LED_OFF; blueLed = LED_OFF; } void ButtonDown(void) { StartHaptic(); redLed = LED_OFF; greenLed = LED_ON; blueLed = LED_OFF; } void ButtonRight(void) { StartHaptic(); redLed = LED_OFF; greenLed = LED_OFF; blueLed = LED_ON; } void ButtonLeft(void) { StartHaptic(); redLed = LED_ON; greenLed = LED_OFF; blueLed = LED_OFF; } void ButtonSlide(void) { StartHaptic(); redLed = LED_ON; greenLed = LED_ON; blueLed = LED_OFF; } int main() { /* Register callbacks to application functions */ kw40z_device.attach_buttonUp(&ButtonUp); kw40z_device.attach_buttonDown(&ButtonDown); kw40z_device.attach_buttonLeft(&ButtonLeft); kw40z_device.attach_buttonRight(&ButtonRight); kw40z_device.attach_buttonSlide(&ButtonSlide); while (true) { Thread::wait(500); } } void StartHaptic(void) { hapticTimer.start(50); haptic = 1; } void StopHaptic(void const *n) { haptic = 0; hapticTimer.stop(); }