Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXAS21002 FXOS8700 Hexi_KW40Z
Fork of Hexi_Buttons_Example by
main.cpp
00001 #include "mbed.h" 00002 #include "Hexi_KW40Z.h" 00003 #include "FXOS8700.h" 00004 #include "FXAS21002.h" 00005 00006 #define LED_ON 0 00007 #define LED_OFF 1 00008 00009 void StartHaptic(void); 00010 void StopHaptic(void const *n); 00011 00012 Serial pc(USBTX, USBRX); 00013 static int count=0; 00014 bool ges_flag=false; 00015 00016 // Pin connections & address for Hexiwear 00017 FXAS21002 gyro(PTC11, PTC10); 00018 FXOS8700 accel(PTC11, PTC10); 00019 FXOS8700 mag(PTC11, PTC10); 00020 Timer t; 00021 00022 DigitalOut redLed(LED1); 00023 DigitalOut greenLed(LED2); 00024 DigitalOut blueLed(LED3); 00025 DigitalOut haptic(PTB9); 00026 00027 /* Define timer for haptic feedback */ 00028 RtosTimer hapticTimer(StopHaptic, osTimerOnce); 00029 00030 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ 00031 KW40Z kw40z_device(PTE24, PTE25); 00032 00033 void ButtonUp(void) 00034 { 00035 StartHaptic(); 00036 count++; 00037 ges_flag=true; 00038 00039 /*redLed = LED_ON; 00040 greenLed = LED_OFF; 00041 blueLed = LED_OFF;*/ 00042 00043 } 00044 00045 void ButtonDown(void) 00046 { 00047 StartHaptic(); 00048 00049 redLed = LED_OFF; 00050 greenLed = LED_ON; 00051 blueLed = LED_OFF; 00052 } 00053 00054 void ButtonRight(void) 00055 { 00056 StartHaptic(); 00057 00058 redLed = LED_OFF; 00059 greenLed = LED_OFF; 00060 blueLed = LED_ON; 00061 } 00062 00063 void ButtonLeft(void) 00064 { 00065 StartHaptic(); 00066 00067 redLed = LED_ON; 00068 greenLed = LED_ON; 00069 blueLed = LED_OFF; 00070 } 00071 00072 void ButtonSlide(void) 00073 { 00074 StartHaptic(); 00075 00076 redLed = LED_ON; 00077 greenLed = LED_ON; 00078 blueLed = LED_ON; 00079 } 00080 00081 int main() 00082 { 00083 /* Register callbacks to application functions */ 00084 kw40z_device.attach_buttonUp(&ButtonUp); 00085 /*kw40z_device.attach_buttonDown(&ButtonDown); 00086 kw40z_device.attach_buttonLeft(&ButtonLeft); 00087 kw40z_device.attach_buttonRight(&ButtonRight); 00088 kw40z_device.attach_buttonSlide(&ButtonSlide);*/ 00089 00090 accel.accel_config(); 00091 mag.mag_config(); 00092 gyro.gyro_config(); 00093 00094 float accel_data[3]; float accel_rms=0.0; 00095 float mag_data[3]; float mag_rms=0.0; 00096 float gyro_data[3]; 00097 00098 while (true) { 00099 if(ges_flag){ 00100 00101 while(count==1){ 00102 00103 ges_flag=false; 00104 t.start(); 00105 //while(1){ 00106 00107 gyro.acquire_gyro_data_dps(gyro_data); 00108 //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); 00109 printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),gyro_data[0],gyro_data[1],gyro_data[2]); 00110 wait(0.01); 00111 00112 accel.acquire_accel_data_g(accel_data); 00113 //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); 00114 printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),accel_data[0],accel_data[1],accel_data[2]); 00115 wait(0.01); 00116 00117 mag.acquire_mag_data_uT(mag_data); 00118 //mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); 00119 printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),mag_data[0],mag_data[1],mag_data[2]); 00120 wait(0.01); 00121 printf("%d\n\r",1); 00122 00123 Thread::wait(500); 00124 } 00125 00126 if(count==2){ 00127 00128 ges_flag=false; 00129 count=0; 00130 gyro.acquire_gyro_data_dps(gyro_data); 00131 //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); 00132 printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),gyro_data[0],gyro_data[1],gyro_data[2]); 00133 wait(0.01); 00134 00135 accel.acquire_accel_data_g(accel_data); 00136 //accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); 00137 printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),accel_data[0],accel_data[1],accel_data[2]); 00138 wait(0.01); 00139 00140 mag.acquire_mag_data_uT(mag_data); 00141 //mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); 00142 printf("%4.5f \t%4.5f \t%4.5f \t%4.5f \n\r",t.read(),mag_data[0],mag_data[1],mag_data[2]); 00143 wait(0.01); 00144 printf("%d\n\r",0); 00145 Thread::wait(500); 00146 00147 t.reset(); 00148 00149 } 00150 00151 00152 00153 00154 00155 } 00156 Thread::wait(50); 00157 } 00158 } 00159 00160 void StartHaptic(void) 00161 { 00162 hapticTimer.start(50); 00163 haptic = 1; 00164 } 00165 00166 void StopHaptic(void const *n) { 00167 haptic = 0; 00168 hapticTimer.stop(); 00169 }
Generated on Tue Jul 12 2022 15:11:54 by
1.7.2
