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:
- 0:f7ef26f17610
- Child:
- 1:80e17bcc26e4
File content as of revision 0:f7ef26f17610:
#include "mbed.h" #include "Hexi_KW40Z.h" #define LED_ON 0 #define LED_OFF 1 void StartHaptic(void); void StopHaptic(void const *n); void HandleButtons(hexi_buttons_t button); kw40z_callbacks_t callbacks = { .buttons = HandleButtons, .alert = NULL, .passkey = NULL, .notifications = NULL, }; 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); int main() { /* Register callbacks to application functions */ kw40z_device.attach(&callbacks); while (true) { Thread::wait(500); } } void HandleButtons(hexi_buttons_t button) { StartHaptic(); switch(button) { case pressUp: redLed = LED_ON; greenLed = LED_OFF; blueLed = LED_OFF; break; case pressDown: redLed = LED_OFF; greenLed = LED_ON; blueLed = LED_OFF; break; case pressLeft: redLed = LED_OFF; greenLed = LED_OFF; blueLed = LED_ON; break; case pressRight: redLed = LED_ON; greenLed = LED_ON; blueLed = LED_OFF; break; case slide: redLed = LED_ON; greenLed = LED_ON; blueLed = LED_ON; break; default: break; } } void StartHaptic(void) { hapticTimer.start(50); haptic = 1; } void StopHaptic(void const *n) { haptic = 0; hapticTimer.stop(); }