A port of the arduino voltmeter example for the mbed using the 4.3' PCT 4d systems touch screen display. Uses the mbed_genie library ported from the arduino visie-genie library by Christian B

Dependencies:   mbed

A test of the arduino voltmeter example using the 4.3' PCT 4d systems touch screen display.

This example program uses the mbed_genie library ported from the arduino Visi-Genie library by Christian B

The display serial TX and RX pins are connected to pin 9 and pin 10 of the mbed microcontroller

The reset pin is not connected as reset function is not implemented

Pin 15 of the mbed has a potentiometer wiper connected to it. The other connections of the potentiometer are connected to +3.3V and 0V - this is to provide some data for the demonstration and to ensure that we don't apply too much voltage to the analogue input pin

For setting up the display in Visie-Genie -

The display has an angular meter object, a LED digits object, two button objects and three static text objects.

The 4dButton0 (On) and the 4dButton1 (Off) button has been set to report on change within Visi-Genie object inspector

The serial baud rate of the display must be set to 115200 baud for this example to work. Ensure you have the settings correct in Visi-Genie when exporting the display program

The mbed program sends digital voltage readings to the LED digits and angular meter of the display module.

The volt readings will only be displayed if the appropriate button on the display is set!

I have written up a more in depth explanation on my blog here:

http://langster1980.blogspot.co.uk/2014/01/ulcd-43-display-mbed-tutorial.html

Revision:
0:1ab681bd453e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jan 05 00:58:09 2014 +0000
@@ -0,0 +1,126 @@
+/* A port test of the arduino voltmeter example using the 
+4.3' PCT 4d systems touch screen display.  
+
+uses the mbed_genie library ported from the arduino
+visie-genie library by Christian B
+
+The display serial TX and RX pins are connected to pin 9
+and pin 10 of the mbed
+
+The reset pin is not connected as reset function is not implemented
+
+Pin 15 of the mbed has a potentiometer wiper connected to it
+The other connections of the potentiometer are connected to +3.3V
+and 0V 
+
+For setting up the display in Visie-Genie
+
+The display has an angular meter objecr, a LED digits object, two buttons 
+and three static text objects.
+
+The program sends digital voltage readings to the LED digits and 
+angular meter of the display module.
+
+The On and Off button has been set to report on change
+
+The baud rate of the display is set to 115200 baud
+
+*/
+
+#include "mbed.h"
+#include "mbed_genie.h"
+
+DigitalOut myled(LED1);   //LED 1 for indication
+
+AnalogIn voltReading(p15);  //Potentiometer wiper connected to pin 15      
+
+int flag = 0;        //holds the "power status" of the voltmeter. flag = 0 means voltmeter is "off", flag = 1 means the voltmeter is "on".
+float voltMeter;       //holds the digital voltage value to be sent to the angular meter
+float voltLED;         //holds the digital voltage value to be sent to the LED digits
+
+//Event handler for the 4d Systems display
+void myGenieEventHandler(void) 
+{
+  genieFrame Event;
+  genieDequeueEvent(&Event);
+  //event report from an object
+  if(Event.reportObject.cmd == GENIE_REPORT_EVENT)
+  {
+    /*
+    for example here we check if we received a message from 4dbuttons objects
+    the index is the button number, refer to the 4dgenie project to know the index
+    */
+    if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)                // If the Reported Message was from a button
+    {
+        if (Event.reportObject.index == 0) 
+        {
+             //printf("Off Button pressed!\n\r");
+             wait(0.2);
+             flag=1;
+        }
+        if (Event.reportObject.index == 1) 
+        {
+             //printf("On Button pressed!\n\r");
+             wait(0.2);
+             flag=0;           
+        }
+    }
+  }
+  
+  //Cmd from a reported object (happens when an object read is requested)
+  // if(Event.reportObject.cmd == GENIE_REPORT_OBJ)
+  // {
+ 
+  // }
+
+}
+ 
+int main() 
+
+{ 
+    SetupGenie();
+    genieAttachEventHandler(&myGenieEventHandler);
+    //genieResetDisplay();
+ 
+    printf("Langsters's mbed Visi-Genie Voltmeter demo \n\r");
+ 
+    genieWriteContrast(15); //set screen contrast to full brightness
+ 
+            while(1) 
+            {   
+                //voltLED = 0;
+                
+                if (flag == 1)
+                    {
+                        //printf("Flag status: %d \r\n", flag);
+                        wait (0.1); 
+                        voltLED = voltReading; 
+                        wait (0.1);    
+                        //printf("Volt bit Reading: %f \n\r",voltLED);
+                        voltLED = voltLED * 3.3;                                    //convert float reading to voltage
+                        //printf("voltLED: %f\r\n",voltLED);
+                
+                        voltLED = voltLED * 1000;
+                        genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, voltLED);      //write to Leddigits0 the value of voltLED 
+                        wait (0.1);
+                        
+                        voltMeter = voltLED/100;
+                        genieWriteObject(GENIE_OBJ_ANGULAR_METER, 0x00, voltMeter); //write to Angularmeter0 the value of voltMeter     
+                    }
+                
+                else if(flag == 0)
+                    
+                    {
+                        //printf("Flag status: %d \r\n", flag); 
+                        wait (0.1);
+                        voltLED = 0;
+                        genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, 0);      //write to Leddigits0 the value of voltLED 
+                        wait (0.1);
+                        
+                        //voltMeter = voltLED/100;
+                        genieWriteObject(GENIE_OBJ_ANGULAR_METER, 0x00, 0); //write to Angularmeter0 the value of voltMeter   
+                    }                            
+                                
+            }
+      
+}        
\ No newline at end of file