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: Hexi_KW40Z Hexi_OLED_SSD1351
Fork of Hexi_Click_Relay-v3_Example by
main.cpp
00001 /* 00002 * Bitmaps need to be formatted as 16bppRgb565, flipped vertically 00003 * and a 6 byte header needs to be appended at the start of the array. 00004 * Use the following tool to create arrays for images. 00005 * https://github.com/MikroElektronika/HEXIWEAR/tree/master/SW/ResourceCollectionTool 00006 * It takes an image and outputs the array. It handles the flipping and the 6 byte header. 00007 * Image needs to be converted outside the tool to fit the screen 00008 * (Max Dimensions:96px by 96px). 00009 */ 00010 00011 #include "mbed.h" 00012 #include "Hexi_OLED_SSD1351.h" 00013 #include "images.h" 00014 #include "Hexi_KW40Z.h" 00015 00016 #define LED_ON 0 00017 #define LED_OFF 1 00018 00019 void StartHaptic(void); 00020 void StopHaptic(void const *n); 00021 00022 /* Instantiate the Click Relay pinout */ 00023 DigitalOut relay1(PTA10); 00024 DigitalOut relay2(PTC4); 00025 00026 /* Instantiate the RGB LED and Haptic motor pinout */ 00027 DigitalOut redLed(LED1); 00028 DigitalOut greenLed(LED2); 00029 DigitalOut blueLed(LED3); 00030 DigitalOut haptic(PTB9); 00031 00032 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ 00033 KW40Z kw40z_device(PTE24, PTE25); 00034 00035 /* Instantiate the SSD1351 OLED Driver */ 00036 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC) 00037 00038 /* Define timer for haptic feedback */ 00039 RtosTimer hapticTimer(StopHaptic, osTimerOnce); 00040 00041 00042 00043 int flag=0; 00044 00045 void ButtonLeft(void) 00046 { 00047 StartHaptic(); 00048 00049 redLed = LED_ON; 00050 greenLed = LED_ON; 00051 blueLed = LED_OFF; 00052 00053 relay2 = !relay2; 00054 flag = 1; 00055 } 00056 00057 void ButtonRight(void) 00058 { 00059 StartHaptic(); 00060 00061 redLed = LED_ON; 00062 greenLed = LED_OFF; 00063 blueLed = LED_OFF; 00064 00065 relay1 = !relay1; 00066 flag = 1; 00067 } 00068 00069 void StartHaptic(void) 00070 { 00071 hapticTimer.start(75); 00072 haptic = 1; 00073 } 00074 00075 void StopHaptic(void const *n) { 00076 haptic = 0; 00077 hapticTimer.stop(); 00078 redLed = LED_OFF; 00079 greenLed = LED_OFF; 00080 blueLed = LED_OFF; 00081 } 00082 00083 int main() { 00084 00085 redLed = LED_OFF; 00086 greenLed = LED_OFF; 00087 blueLed = LED_OFF; 00088 00089 /* Pointer for the image to be displayed */ 00090 const uint8_t *image1; 00091 const uint8_t *image2; 00092 const uint8_t *image3; 00093 00094 /* Setting pointer location of the 96 by 96 pixel bitmap */ 00095 image1 = Relay_OFF; 00096 image2 = Button_OFF; 00097 image3 = Button_ON; 00098 00099 /* Turn on the backlight of the OLED Display */ 00100 oled.DimScreenON(); 00101 00102 /* Register callbacks to application functions */ 00103 kw40z_device.attach_buttonLeft(&ButtonLeft); 00104 kw40z_device.attach_buttonRight(&ButtonRight); 00105 00106 /* Fill the screen with white to overwrite previous image */ 00107 oled.FillScreen(COLOR_BLACK); 00108 00109 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */ 00110 oled.DrawImage(image1,0,0); 00111 00112 while (true) 00113 { 00114 00115 if (flag == 1) 00116 { 00117 if (relay2==0) 00118 { 00119 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */ 00120 oled.DrawImage(image2,9,25); 00121 } 00122 else 00123 { 00124 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */ 00125 oled.DrawImage(image3,9,25); 00126 } 00127 if (relay1==0) 00128 { 00129 /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/ 00130 oled.DrawImage(image2,54,25); 00131 } 00132 else 00133 { 00134 /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/ 00135 oled.DrawImage(image3,54,25); 00136 } 00137 flag = 0; 00138 } 00139 Thread::wait(50); 00140 } 00141 }
Generated on Wed Jul 13 2022 09:07:56 by
1.7.2
