![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Chrono Tir
main.cpp@0:98f39b4055ea, 2020-02-03 (annotated)
- Committer:
- pathae
- Date:
- Mon Feb 03 14:29:14 2020 +0000
- Revision:
- 0:98f39b4055ea
chrono_tir_V2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pathae | 0:98f39b4055ea | 1 | /* A port test of the arduino voltmeter example using the |
pathae | 0:98f39b4055ea | 2 | 4.3' PCT 4d systems touch screen display. |
pathae | 0:98f39b4055ea | 3 | |
pathae | 0:98f39b4055ea | 4 | uses the mbed_genie library ported from the arduino |
pathae | 0:98f39b4055ea | 5 | visie-genie library by Christian B |
pathae | 0:98f39b4055ea | 6 | |
pathae | 0:98f39b4055ea | 7 | The display serial TX and RX pins are connected to pin 9 |
pathae | 0:98f39b4055ea | 8 | and pin 10 of the mbed |
pathae | 0:98f39b4055ea | 9 | |
pathae | 0:98f39b4055ea | 10 | The reset pin is not connected as reset function is not implemented |
pathae | 0:98f39b4055ea | 11 | |
pathae | 0:98f39b4055ea | 12 | Pin 15 of the mbed has a potentiometer wiper connected to it |
pathae | 0:98f39b4055ea | 13 | The other connections of the potentiometer are connected to +3.3V |
pathae | 0:98f39b4055ea | 14 | and 0V |
pathae | 0:98f39b4055ea | 15 | |
pathae | 0:98f39b4055ea | 16 | For setting up the display in Visie-Genie |
pathae | 0:98f39b4055ea | 17 | |
pathae | 0:98f39b4055ea | 18 | The display has an angular meter objecr, a LED digits object, two buttons |
pathae | 0:98f39b4055ea | 19 | and three static text objects. |
pathae | 0:98f39b4055ea | 20 | |
pathae | 0:98f39b4055ea | 21 | The program sends digital voltage readings to the LED digits and |
pathae | 0:98f39b4055ea | 22 | angular meter of the display module. |
pathae | 0:98f39b4055ea | 23 | |
pathae | 0:98f39b4055ea | 24 | The On and Off button has been set to report on change |
pathae | 0:98f39b4055ea | 25 | |
pathae | 0:98f39b4055ea | 26 | The baud rate of the display is set to 115200 baud |
pathae | 0:98f39b4055ea | 27 | |
pathae | 0:98f39b4055ea | 28 | */ |
pathae | 0:98f39b4055ea | 29 | |
pathae | 0:98f39b4055ea | 30 | #include "mbed.h" |
pathae | 0:98f39b4055ea | 31 | #include "mbed_genie.h" |
pathae | 0:98f39b4055ea | 32 | |
pathae | 0:98f39b4055ea | 33 | DigitalOut myled(LED1); //LED 1 for indication |
pathae | 0:98f39b4055ea | 34 | |
pathae | 0:98f39b4055ea | 35 | AnalogIn voltReading(PC_0); //Potentiometer wiper connected to pin 15 |
pathae | 0:98f39b4055ea | 36 | |
pathae | 0:98f39b4055ea | 37 | int flag = 0; //holds the "power status" of the voltmeter. flag = 0 means voltmeter is "off", flag = 1 means the voltmeter is "on". |
pathae | 0:98f39b4055ea | 38 | float voltMeter; //holds the digital voltage value to be sent to the angular meter |
pathae | 0:98f39b4055ea | 39 | float voltLED; //holds the digital voltage value to be sent to the LED digits |
pathae | 0:98f39b4055ea | 40 | |
pathae | 0:98f39b4055ea | 41 | //Event handler for the 4d Systems display |
pathae | 0:98f39b4055ea | 42 | void myGenieEventHandler(void) |
pathae | 0:98f39b4055ea | 43 | { |
pathae | 0:98f39b4055ea | 44 | genieFrame Event; |
pathae | 0:98f39b4055ea | 45 | genieDequeueEvent(&Event); |
pathae | 0:98f39b4055ea | 46 | //event report from an object |
pathae | 0:98f39b4055ea | 47 | if(Event.reportObject.cmd == GENIE_REPORT_EVENT) { |
pathae | 0:98f39b4055ea | 48 | /* |
pathae | 0:98f39b4055ea | 49 | for example here we check if we received a message from 4dbuttons objects |
pathae | 0:98f39b4055ea | 50 | the index is the button number, refer to the 4dgenie project to know the index |
pathae | 0:98f39b4055ea | 51 | */ |
pathae | 0:98f39b4055ea | 52 | if (Event.reportObject.object == GENIE_OBJ_4DBUTTON) { // If the Reported Message was from a button |
pathae | 0:98f39b4055ea | 53 | if (Event.reportObject.index == 0) { |
pathae | 0:98f39b4055ea | 54 | //printf("Off Button pressed!\n\r"); |
pathae | 0:98f39b4055ea | 55 | wait(0.2); |
pathae | 0:98f39b4055ea | 56 | flag=1; |
pathae | 0:98f39b4055ea | 57 | } |
pathae | 0:98f39b4055ea | 58 | if (Event.reportObject.index == 1) { |
pathae | 0:98f39b4055ea | 59 | //printf("On Button pressed!\n\r"); |
pathae | 0:98f39b4055ea | 60 | wait(0.2); |
pathae | 0:98f39b4055ea | 61 | flag=0; |
pathae | 0:98f39b4055ea | 62 | } |
pathae | 0:98f39b4055ea | 63 | } |
pathae | 0:98f39b4055ea | 64 | } |
pathae | 0:98f39b4055ea | 65 | |
pathae | 0:98f39b4055ea | 66 | //Cmd from a reported object (happens when an object read is requested) |
pathae | 0:98f39b4055ea | 67 | // if(Event.reportObject.cmd == GENIE_REPORT_OBJ) |
pathae | 0:98f39b4055ea | 68 | // { |
pathae | 0:98f39b4055ea | 69 | |
pathae | 0:98f39b4055ea | 70 | // } |
pathae | 0:98f39b4055ea | 71 | |
pathae | 0:98f39b4055ea | 72 | } |
pathae | 0:98f39b4055ea | 73 | |
pathae | 0:98f39b4055ea | 74 | int main() |
pathae | 0:98f39b4055ea | 75 | |
pathae | 0:98f39b4055ea | 76 | { |
pathae | 0:98f39b4055ea | 77 | SetupGenie(); |
pathae | 0:98f39b4055ea | 78 | genieAttachEventHandler(&myGenieEventHandler); |
pathae | 0:98f39b4055ea | 79 | //genieResetDisplay(); |
pathae | 0:98f39b4055ea | 80 | |
pathae | 0:98f39b4055ea | 81 | printf("Langsters's mbed Visi-Genie Voltmeter demo \n\r"); |
pathae | 0:98f39b4055ea | 82 | |
pathae | 0:98f39b4055ea | 83 | //genieWriteContrast(15); //set screen contrast to full brightness |
pathae | 0:98f39b4055ea | 84 | |
pathae | 0:98f39b4055ea | 85 | voltLED = 0.1; |
pathae | 0:98f39b4055ea | 86 | while(1) { |
pathae | 0:98f39b4055ea | 87 | printf("Test1\n\r"); |
pathae | 0:98f39b4055ea | 88 | //voltLED = 0; |
pathae | 0:98f39b4055ea | 89 | |
pathae | 0:98f39b4055ea | 90 | if (flag == 1) { |
pathae | 0:98f39b4055ea | 91 | //printf("Flag status: %d \r\n", flag); |
pathae | 0:98f39b4055ea | 92 | /* wait (0.1); |
pathae | 0:98f39b4055ea | 93 | voltLED = voltReading; |
pathae | 0:98f39b4055ea | 94 | wait (0.1); |
pathae | 0:98f39b4055ea | 95 | //printf("Volt bit Reading: %f \n\r",voltLED); |
pathae | 0:98f39b4055ea | 96 | voltLED = voltLED * 3.3; //convert float reading to voltage |
pathae | 0:98f39b4055ea | 97 | //printf("voltLED: %f\r\n",voltLED); |
pathae | 0:98f39b4055ea | 98 | |
pathae | 0:98f39b4055ea | 99 | // voltLED = voltLED * 1000; |
pathae | 0:98f39b4055ea | 100 | voltLED = 2.2; |
pathae | 0:98f39b4055ea | 101 | printf("voltLED: %f\r\n",voltLED); |
pathae | 0:98f39b4055ea | 102 | genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, voltLED); //write to Leddigits0 the value of voltLED |
pathae | 0:98f39b4055ea | 103 | //wait (0.1); |
pathae | 0:98f39b4055ea | 104 | wait (1); |
pathae | 0:98f39b4055ea | 105 | voltMeter = voltLED/100; |
pathae | 0:98f39b4055ea | 106 | genieWriteObject(GENIE_OBJ_ANGULAR_METER, 0x00, voltMeter); //write to Angularmeter0 the value of voltMeter*/ |
pathae | 0:98f39b4055ea | 107 | } |
pathae | 0:98f39b4055ea | 108 | |
pathae | 0:98f39b4055ea | 109 | else if(flag == 0) |
pathae | 0:98f39b4055ea | 110 | |
pathae | 0:98f39b4055ea | 111 | { |
pathae | 0:98f39b4055ea | 112 | //printf("Flag status: %d \r\n", flag); |
pathae | 0:98f39b4055ea | 113 | /* wait (0.1); |
pathae | 0:98f39b4055ea | 114 | voltLED = 0; |
pathae | 0:98f39b4055ea | 115 | genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, 0); //write to Leddigits0 the value of voltLED |
pathae | 0:98f39b4055ea | 116 | wait (0.1); |
pathae | 0:98f39b4055ea | 117 | |
pathae | 0:98f39b4055ea | 118 | //voltMeter = voltLED/100; |
pathae | 0:98f39b4055ea | 119 | genieWriteObject(GENIE_OBJ_ANGULAR_METER, 0x00, 0); //write to Angularmeter0 the value of voltMeter |
pathae | 0:98f39b4055ea | 120 | */ |
pathae | 0:98f39b4055ea | 121 | voltLED = voltLED + 0.1;; |
pathae | 0:98f39b4055ea | 122 | printf("voltLED: %f\r\n",voltLED); |
pathae | 0:98f39b4055ea | 123 | genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x00, voltLED*100); |
pathae | 0:98f39b4055ea | 124 | wait (0.5); |
pathae | 0:98f39b4055ea | 125 | genieWriteObject(GENIE_OBJ_ANGULAR_METER, 0x00, voltLED*20); //write to Angularmeter0 the value of voltMeter |
pathae | 0:98f39b4055ea | 126 | } |
pathae | 0:98f39b4055ea | 127 | |
pathae | 0:98f39b4055ea | 128 | } |
pathae | 0:98f39b4055ea | 129 | |
pathae | 0:98f39b4055ea | 130 | } |