A simple program to demonstrate how to use a RockerSW object on the 4D systems touch screen display with the mbed as a host microcontroller

Dependencies:   mbed

This is a demonstration program on how to use a 4D systems touch screen display with the mbed as a host microcontroller. For more information please take a look at the corresponding blog post here:

http://langster1980.blogspot.co.uk/2014/07/mbed-4d-systems-display-tutorial-with.html

Here is a photo of the breadboard layout and a schematic:

/media/uploads/langster1980/pwm_tutorial_schematic.png

/media/uploads/langster1980/mbed_breadboard_layout.jpg

Committer:
langster1980
Date:
Fri Jul 04 18:38:04 2014 +0000
Revision:
1:f16b26f664f9
Parent:
0:81f5d5b70036
1st commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
langster1980 0:81f5d5b70036 1 /* An mbed tutorial example using the
langster1980 0:81f5d5b70036 2 4.3' PCT 4d systems touch screen display.
langster1980 0:81f5d5b70036 3
langster1980 0:81f5d5b70036 4 uses the mbed_genie library ported from the arduino
langster1980 0:81f5d5b70036 5 visie-genie library by Christian B
langster1980 0:81f5d5b70036 6
langster1980 0:81f5d5b70036 7 The display serial TX and RX pins are connected to pin 9
langster1980 0:81f5d5b70036 8 and pin 10 of the mbed, the reset pin is connected to pin 11
langster1980 0:81f5d5b70036 9
langster1980 0:81f5d5b70036 10 For setting up the display in Visie-Genie
langster1980 0:81f5d5b70036 11
langster1980 0:81f5d5b70036 12 The display has a rocker switch object, an LED object,
langster1980 0:81f5d5b70036 13 and a slider object.
langster1980 0:81f5d5b70036 14
langster1980 0:81f5d5b70036 15 The program reads the status of the rocker switch
langster1980 0:81f5d5b70036 16 and was supposed to turn on the LED.
langster1980 0:81f5d5b70036 17
langster1980 0:81f5d5b70036 18 The slider adjusts the flash rate of the LED
langster1980 0:81f5d5b70036 19
langster1980 0:81f5d5b70036 20 The baud rate of the display is set to 115200 baud
langster1980 0:81f5d5b70036 21
langster1980 0:81f5d5b70036 22 The Mbed4dGenie class requires 3 parameters
langster1980 0:81f5d5b70036 23 1 - Tx pin
langster1980 0:81f5d5b70036 24 2 - Rx pin
langster1980 0:81f5d5b70036 25 3 - Reset pin
langster1980 0:81f5d5b70036 26 */
langster1980 0:81f5d5b70036 27
langster1980 0:81f5d5b70036 28 #include "mbed.h"
langster1980 0:81f5d5b70036 29 #include "mbed_genie.h"
langster1980 0:81f5d5b70036 30
langster1980 0:81f5d5b70036 31 Mbed4dGenie lcd4d(p9,p10,p11);
langster1980 0:81f5d5b70036 32
langster1980 0:81f5d5b70036 33 DigitalOut whiteLED(p26); //LED 1 for indication
langster1980 0:81f5d5b70036 34 int rockersw_val = 0; //holds the status of the 4Dbutton0 Object
langster1980 0:81f5d5b70036 35
langster1980 0:81f5d5b70036 36 int sliderRead = 0;
langster1980 0:81f5d5b70036 37 float flashRate = 1; //variable to store LED flash rate
langster1980 0:81f5d5b70036 38 int flag = 0; //flag variable to store rockerswitch state
langster1980 0:81f5d5b70036 39
langster1980 0:81f5d5b70036 40 //Event handler for the 4d Systems display
langster1980 0:81f5d5b70036 41 void myGenieEventHandler(void)
langster1980 0:81f5d5b70036 42 {
langster1980 0:81f5d5b70036 43 genieFrame Event;
langster1980 0:81f5d5b70036 44 lcd4d.genieDequeueEvent(&Event);
langster1980 1:f16b26f664f9 45
langster1980 0:81f5d5b70036 46 //event report from an object
langster1980 0:81f5d5b70036 47 if(Event.reportObject.cmd == GENIE_REPORT_EVENT) {
langster1980 0:81f5d5b70036 48 if (Event.reportObject.object == GENIE_OBJ_ROCKERSW) { // If the Reported Message was from a rocker switch
langster1980 0:81f5d5b70036 49 if (Event.reportObject.index == 0) {
langster1980 0:81f5d5b70036 50 printf("Rocker switch 0 pressed!\n\r");
langster1980 0:81f5d5b70036 51 rockersw_val = lcd4d.genieGetEventData(&Event); //extract the MSB and LSB values and pass them to rockersw_val
langster1980 0:81f5d5b70036 52
langster1980 0:81f5d5b70036 53 if (rockersw_val == 0) { //if Rockerswitch0 is off
langster1980 0:81f5d5b70036 54 flag = 0; //"turn off" the LED
langster1980 0:81f5d5b70036 55 printf("Rocker switch switch in off state\n\r"); //print a serial message for debugging
langster1980 0:81f5d5b70036 56 }
langster1980 0:81f5d5b70036 57
langster1980 0:81f5d5b70036 58 else if (rockersw_val == 1) { //if Rockerswitch0 is on
langster1980 0:81f5d5b70036 59 flag = 1; //"turn on" the LED
langster1980 0:81f5d5b70036 60 printf("Rocker switch switch in ON state\n\r"); //print a serial message for debugging
langster1980 0:81f5d5b70036 61 }
langster1980 0:81f5d5b70036 62 }
langster1980 0:81f5d5b70036 63 }
langster1980 0:81f5d5b70036 64
langster1980 0:81f5d5b70036 65 if (Event.reportObject.object == GENIE_OBJ_SLIDER) { // If the Reported Message was from a slider object
langster1980 0:81f5d5b70036 66 if (Event.reportObject.index == 0) { // If the slider object was slider0
langster1980 0:81f5d5b70036 67 printf("Slider object changed!\n\r"); // Display a serial message for debugging
langster1980 0:81f5d5b70036 68 sliderRead = lcd4d.genieGetEventData(&Event); // Read the current silder0 value
langster1980 0:81f5d5b70036 69 printf("SliderRead = %d \n\r", sliderRead); // Display the Slider0 value
langster1980 0:81f5d5b70036 70 flashRate = 0.01; // Set flash rate initially to 10 ms On / Off
langster1980 0:81f5d5b70036 71 flashRate = 1 - (flashRate * sliderRead); // Apply the value of slider0 object to flashRate
langster1980 1:f16b26f664f9 72
langster1980 0:81f5d5b70036 73
langster1980 0:81f5d5b70036 74 }
langster1980 0:81f5d5b70036 75
langster1980 0:81f5d5b70036 76 //Cmd from a reported object (happens when an object read is requested)
langster1980 0:81f5d5b70036 77 if(Event.reportObject.cmd == GENIE_REPORT_OBJ) {
langster1980 0:81f5d5b70036 78
langster1980 0:81f5d5b70036 79 }
langster1980 0:81f5d5b70036 80 }
langster1980 0:81f5d5b70036 81 }
langster1980 0:81f5d5b70036 82 }
langster1980 0:81f5d5b70036 83
langster1980 0:81f5d5b70036 84 int main()
langster1980 0:81f5d5b70036 85
langster1980 0:81f5d5b70036 86 {
langster1980 0:81f5d5b70036 87 lcd4d.genieAttachEventHandler(&myGenieEventHandler); // Call the event handler for the 4D display
langster1980 1:f16b26f664f9 88
langster1980 0:81f5d5b70036 89 lcd4d.genieWriteContrast(0); // Set the display contrast to 0 initially
langster1980 0:81f5d5b70036 90
langster1980 0:81f5d5b70036 91 lcd4d.genieWriteContrast(15); // Set the display contrast to 15 (full brightness)
langster1980 0:81f5d5b70036 92
langster1980 0:81f5d5b70036 93 printf("Langsters's mbed Visi-Genie LED Flash demo \n\r"); // Display a welcome message on the serial monitor
langster1980 0:81f5d5b70036 94
langster1980 0:81f5d5b70036 95 while(1) { // initialise an infinite while loop
langster1980 1:f16b26f664f9 96
langster1980 0:81f5d5b70036 97 if(flag == 1) { // Check if rockerSW object has been activated
langster1980 0:81f5d5b70036 98 whiteLED = 1; // turn real LED ON
langster1980 0:81f5d5b70036 99 wait(flashRate); // keep LED on for a short period of time
langster1980 0:81f5d5b70036 100 whiteLED = 0; // turn real LED ON
langster1980 0:81f5d5b70036 101 wait(flashRate); // turn LED off for a short period of time
langster1980 1:f16b26f664f9 102
langster1980 0:81f5d5b70036 103 }
langster1980 0:81f5d5b70036 104
langster1980 0:81f5d5b70036 105 if(flag == 0) { // Check if rockerSW object has been deactivated
langster1980 0:81f5d5b70036 106 whiteLED = 0; // turn real LED OFF
langster1980 0:81f5d5b70036 107 }
langster1980 0:81f5d5b70036 108 }
langster1980 0:81f5d5b70036 109 }
langster1980 0:81f5d5b70036 110
langster1980 0:81f5d5b70036 111