Click Relay example for Hexiwear featuring Display, Touch buttons and Haptic feedback

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351

Fork of Hexi_Click_Relay-v3_Example by Hexiwear

This project demonstrates the use of the Mikroelektronika Click Relay module with hexiwear featuring the OLED display, the Touch buttons and Haptic feedback

Plug Hexiwear into the Docking Station and the RELAY Click to the Click Socket 1
Connect the USB cable to your computer and to the micro-USB port of the Docking Station

Compile the project and copy the binary "Hexi_Click_Relay-v3_Example_HEXIWEAR.bin" in the DAP-LINK drive from your computer file explorer
Press the K64F-RESET button on the docking station to start the program on your board

The OLED screen will display two switch graphics with both relays in position OFF
Touch the left or right electrodes/buttons located below the screen to control the relay 1 or 2
Screen will update the graphics to reflect the status of the each relay either ON or OFF
Haptic motor will vibrate to acknowledge that a touch command has been received
RGB LED will briefly turn orange for Relay 1 and red for Relay 2 position change.

Committer:
GregC
Date:
Tue Sep 20 21:51:57 2016 +0000
Revision:
0:ac93d26bbdb5
Child:
1:420b0ad324f8
Click Relay example for Hexiwear featuring Display, Touch buttons and Haptic feedback

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregC 0:ac93d26bbdb5 1 /*
GregC 0:ac93d26bbdb5 2 * Bitmaps need to be formatted as 16bppRgb565, flipped vertically
GregC 0:ac93d26bbdb5 3 * and a 6 byte header needs to be appended at the start of the array.
GregC 0:ac93d26bbdb5 4 * Use the following tool to create arrays for images.
GregC 0:ac93d26bbdb5 5 * https://github.com/MikroElektronika/HEXIWEAR/tree/master/SW/ResourceCollectionTool
GregC 0:ac93d26bbdb5 6 * It takes an image and outputs the array. It handles the flipping and the 6 byte header.
GregC 0:ac93d26bbdb5 7 * Image needs to be converted outside the tool to fit the screen
GregC 0:ac93d26bbdb5 8 * (Max Dimensions:96px by 96px).
GregC 0:ac93d26bbdb5 9 */
GregC 0:ac93d26bbdb5 10
GregC 0:ac93d26bbdb5 11 #include "mbed.h"
GregC 0:ac93d26bbdb5 12 #include "Hexi_OLED_SSD1351.h"
GregC 0:ac93d26bbdb5 13 #include "images.h"
GregC 0:ac93d26bbdb5 14 #include "Hexi_KW40Z.h"
GregC 0:ac93d26bbdb5 15
GregC 0:ac93d26bbdb5 16 #define LED_ON 0
GregC 0:ac93d26bbdb5 17 #define LED_OFF 1
GregC 0:ac93d26bbdb5 18
GregC 0:ac93d26bbdb5 19 void StartHaptic(void);
GregC 0:ac93d26bbdb5 20 void StopHaptic(void const *n);
GregC 0:ac93d26bbdb5 21
GregC 0:ac93d26bbdb5 22 /* Instantiate the Click Relay pinout */
GregC 0:ac93d26bbdb5 23 DigitalOut relay1(PTA10);
GregC 0:ac93d26bbdb5 24 DigitalOut relay2(PTC4);
GregC 0:ac93d26bbdb5 25
GregC 0:ac93d26bbdb5 26 /* Instantiate the RGB LED and Haptic motor pinout */
GregC 0:ac93d26bbdb5 27 DigitalOut redLed(LED1);
GregC 0:ac93d26bbdb5 28 DigitalOut greenLed(LED2);
GregC 0:ac93d26bbdb5 29 DigitalOut blueLed(LED3);
GregC 0:ac93d26bbdb5 30 DigitalOut haptic(PTB9);
GregC 0:ac93d26bbdb5 31
GregC 0:ac93d26bbdb5 32 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
GregC 0:ac93d26bbdb5 33 KW40Z kw40z_device(PTE24, PTE25);
GregC 0:ac93d26bbdb5 34
GregC 0:ac93d26bbdb5 35 /* Instantiate the SSD1351 OLED Driver */
GregC 0:ac93d26bbdb5 36 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
GregC 0:ac93d26bbdb5 37
GregC 0:ac93d26bbdb5 38 /* Define timer for haptic feedback */
GregC 0:ac93d26bbdb5 39 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
GregC 0:ac93d26bbdb5 40
GregC 0:ac93d26bbdb5 41
GregC 0:ac93d26bbdb5 42
GregC 0:ac93d26bbdb5 43 int flag=0;
GregC 0:ac93d26bbdb5 44
GregC 0:ac93d26bbdb5 45 void ButtonLeft(void)
GregC 0:ac93d26bbdb5 46 {
GregC 0:ac93d26bbdb5 47 StartHaptic();
GregC 0:ac93d26bbdb5 48
GregC 0:ac93d26bbdb5 49 redLed = LED_ON;
GregC 0:ac93d26bbdb5 50 greenLed = LED_ON;
GregC 0:ac93d26bbdb5 51 blueLed = LED_OFF;
GregC 0:ac93d26bbdb5 52
GregC 0:ac93d26bbdb5 53 relay2 = !relay2;
GregC 0:ac93d26bbdb5 54 flag = 1;
GregC 0:ac93d26bbdb5 55 }
GregC 0:ac93d26bbdb5 56
GregC 0:ac93d26bbdb5 57 void ButtonRight(void)
GregC 0:ac93d26bbdb5 58 {
GregC 0:ac93d26bbdb5 59 StartHaptic();
GregC 0:ac93d26bbdb5 60
GregC 0:ac93d26bbdb5 61 redLed = LED_ON;
GregC 0:ac93d26bbdb5 62 greenLed = LED_OFF;
GregC 0:ac93d26bbdb5 63 blueLed = LED_OFF;
GregC 0:ac93d26bbdb5 64
GregC 0:ac93d26bbdb5 65 relay1 = !relay1;
GregC 0:ac93d26bbdb5 66 flag = 1;
GregC 0:ac93d26bbdb5 67 }
GregC 0:ac93d26bbdb5 68
GregC 0:ac93d26bbdb5 69 void StartHaptic(void)
GregC 0:ac93d26bbdb5 70 {
GregC 0:ac93d26bbdb5 71 hapticTimer.start(75);
GregC 0:ac93d26bbdb5 72 haptic = 1;
GregC 0:ac93d26bbdb5 73 }
GregC 0:ac93d26bbdb5 74
GregC 0:ac93d26bbdb5 75 void StopHaptic(void const *n) {
GregC 0:ac93d26bbdb5 76 haptic = 0;
GregC 0:ac93d26bbdb5 77 hapticTimer.stop();
GregC 0:ac93d26bbdb5 78 redLed = LED_OFF;
GregC 0:ac93d26bbdb5 79 greenLed = LED_OFF;
GregC 0:ac93d26bbdb5 80 blueLed = LED_OFF;
GregC 0:ac93d26bbdb5 81 }
GregC 0:ac93d26bbdb5 82
GregC 0:ac93d26bbdb5 83 int main() {
GregC 0:ac93d26bbdb5 84
GregC 0:ac93d26bbdb5 85 redLed = LED_OFF;
GregC 0:ac93d26bbdb5 86 greenLed = LED_OFF;
GregC 0:ac93d26bbdb5 87 blueLed = LED_OFF;
GregC 0:ac93d26bbdb5 88
GregC 0:ac93d26bbdb5 89 /* Pointer for the image to be displayed */
GregC 0:ac93d26bbdb5 90 const uint8_t *image1;
GregC 0:ac93d26bbdb5 91 const uint8_t *image2;
GregC 0:ac93d26bbdb5 92 const uint8_t *image3;
GregC 0:ac93d26bbdb5 93 const uint8_t *image4;
GregC 0:ac93d26bbdb5 94
GregC 0:ac93d26bbdb5 95 /* Setting pointer location of the 96 by 96 pixel bitmap */
GregC 0:ac93d26bbdb5 96 image1 = Relay_FF;
GregC 0:ac93d26bbdb5 97 image2 = Relay_NN;
GregC 0:ac93d26bbdb5 98 image3 = Relay_FN;
GregC 0:ac93d26bbdb5 99 image4 = Relay_NF;
GregC 0:ac93d26bbdb5 100
GregC 0:ac93d26bbdb5 101 /* Turn on the backlight of the OLED Display */
GregC 0:ac93d26bbdb5 102 oled.DimScreenON();
GregC 0:ac93d26bbdb5 103
GregC 0:ac93d26bbdb5 104 /* Register callbacks to application functions */
GregC 0:ac93d26bbdb5 105 kw40z_device.attach_buttonLeft(&ButtonLeft);
GregC 0:ac93d26bbdb5 106 kw40z_device.attach_buttonRight(&ButtonRight);
GregC 0:ac93d26bbdb5 107
GregC 0:ac93d26bbdb5 108 /* Fill the screen with white to overwrite previous image */
GregC 0:ac93d26bbdb5 109 oled.FillScreen(COLOR_BLACK);
GregC 0:ac93d26bbdb5 110
GregC 0:ac93d26bbdb5 111 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
GregC 0:ac93d26bbdb5 112 oled.DrawImage(image1,0,0);
GregC 0:ac93d26bbdb5 113
GregC 0:ac93d26bbdb5 114 while (true) {
GregC 0:ac93d26bbdb5 115
GregC 0:ac93d26bbdb5 116 if (flag == 1) {
GregC 0:ac93d26bbdb5 117 if (relay2==0) {
GregC 0:ac93d26bbdb5 118 if (relay1==0) {
GregC 0:ac93d26bbdb5 119 /* Fill the screen with white to overwrite previous image */
GregC 0:ac93d26bbdb5 120 oled.FillScreen(COLOR_BLACK);
GregC 0:ac93d26bbdb5 121
GregC 0:ac93d26bbdb5 122 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
GregC 0:ac93d26bbdb5 123 oled.DrawImage(image1,0,0);
GregC 0:ac93d26bbdb5 124 }
GregC 0:ac93d26bbdb5 125 else {
GregC 0:ac93d26bbdb5 126 /* Fill the screen with white to overwrite previous image */
GregC 0:ac93d26bbdb5 127 oled.FillScreen(COLOR_BLACK);
GregC 0:ac93d26bbdb5 128
GregC 0:ac93d26bbdb5 129 /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/
GregC 0:ac93d26bbdb5 130 oled.DrawImage(image3,0,0);
GregC 0:ac93d26bbdb5 131 }
GregC 0:ac93d26bbdb5 132 }
GregC 0:ac93d26bbdb5 133 else {
GregC 0:ac93d26bbdb5 134 if (relay1==0) {
GregC 0:ac93d26bbdb5 135 /* Fill the screen with white to overwrite previous image */
GregC 0:ac93d26bbdb5 136 oled.FillScreen(COLOR_BLACK);
GregC 0:ac93d26bbdb5 137
GregC 0:ac93d26bbdb5 138 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
GregC 0:ac93d26bbdb5 139 oled.DrawImage(image4,0,0);
GregC 0:ac93d26bbdb5 140 }
GregC 0:ac93d26bbdb5 141 else {
GregC 0:ac93d26bbdb5 142 /* Fill the screen with white to overwrite previous image */
GregC 0:ac93d26bbdb5 143 oled.FillScreen(COLOR_BLACK);
GregC 0:ac93d26bbdb5 144
GregC 0:ac93d26bbdb5 145 /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/
GregC 0:ac93d26bbdb5 146 oled.DrawImage(image2,0,0);
GregC 0:ac93d26bbdb5 147 }
GregC 0:ac93d26bbdb5 148 }
GregC 0:ac93d26bbdb5 149 flag = 0;
GregC 0:ac93d26bbdb5 150 }
GregC 0:ac93d26bbdb5 151 Thread::wait(50);
GregC 0:ac93d26bbdb5 152 }
GregC 0:ac93d26bbdb5 153 }