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:
Wed Sep 21 23:05:11 2016 +0000
Revision:
1:420b0ad324f8
Parent:
0:ac93d26bbdb5
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
GregC 0:ac93d26bbdb5 94 /* Setting pointer location of the 96 by 96 pixel bitmap */
GregC 1:420b0ad324f8 95 image1 = Relay_OFF;
GregC 1:420b0ad324f8 96 image2 = Button_OFF;
GregC 1:420b0ad324f8 97 image3 = Button_ON;
GregC 0:ac93d26bbdb5 98
GregC 0:ac93d26bbdb5 99 /* Turn on the backlight of the OLED Display */
GregC 0:ac93d26bbdb5 100 oled.DimScreenON();
GregC 0:ac93d26bbdb5 101
GregC 0:ac93d26bbdb5 102 /* Register callbacks to application functions */
GregC 0:ac93d26bbdb5 103 kw40z_device.attach_buttonLeft(&ButtonLeft);
GregC 0:ac93d26bbdb5 104 kw40z_device.attach_buttonRight(&ButtonRight);
GregC 0:ac93d26bbdb5 105
GregC 0:ac93d26bbdb5 106 /* Fill the screen with white to overwrite previous image */
GregC 0:ac93d26bbdb5 107 oled.FillScreen(COLOR_BLACK);
GregC 0:ac93d26bbdb5 108
GregC 0:ac93d26bbdb5 109 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
GregC 0:ac93d26bbdb5 110 oled.DrawImage(image1,0,0);
GregC 0:ac93d26bbdb5 111
GregC 1:420b0ad324f8 112 while (true)
GregC 1:420b0ad324f8 113 {
GregC 0:ac93d26bbdb5 114
GregC 1:420b0ad324f8 115 if (flag == 1)
GregC 1:420b0ad324f8 116 {
GregC 1:420b0ad324f8 117 if (relay2==0)
GregC 1:420b0ad324f8 118 {
GregC 1:420b0ad324f8 119 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
GregC 1:420b0ad324f8 120 oled.DrawImage(image2,9,25);
GregC 1:420b0ad324f8 121 }
GregC 1:420b0ad324f8 122 else
GregC 1:420b0ad324f8 123 {
GregC 1:420b0ad324f8 124 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
GregC 1:420b0ad324f8 125 oled.DrawImage(image3,9,25);
GregC 1:420b0ad324f8 126 }
GregC 1:420b0ad324f8 127 if (relay1==0)
GregC 1:420b0ad324f8 128 {
GregC 1:420b0ad324f8 129 /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/
GregC 1:420b0ad324f8 130 oled.DrawImage(image2,54,25);
GregC 1:420b0ad324f8 131 }
GregC 1:420b0ad324f8 132 else
GregC 1:420b0ad324f8 133 {
GregC 1:420b0ad324f8 134 /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/
GregC 1:420b0ad324f8 135 oled.DrawImage(image3,54,25);
GregC 1:420b0ad324f8 136 }
GregC 1:420b0ad324f8 137 flag = 0;
GregC 1:420b0ad324f8 138 }
GregC 1:420b0ad324f8 139 Thread::wait(50);
GregC 0:ac93d26bbdb5 140 }
GregC 0:ac93d26bbdb5 141 }