![](/media/cache/profiles/06833b73c7b85d172f55b6f38a40b094.jpg.50x50_q85.jpg)
a quick program to test the 4Dgenie library
Fork of Genie_Test by
main.cpp@6:120a0a3ff2e1, 2014-07-06 (annotated)
- Committer:
- langster1980
- Date:
- Sun Jul 06 22:17:07 2014 +0000
- Revision:
- 6:120a0a3ff2e1
- Parent:
- 5:b1e5af95a2fb
a quick demo program to test 4dGENIE library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris215 | 0:f065693322dd | 1 | #include "mbed.h" |
chris215 | 0:f065693322dd | 2 | #include "mbed_genie.h" |
chris215 | 3:4fe144f2f64e | 3 | |
langster1980 | 6:120a0a3ff2e1 | 4 | #define beta 3977 // from the thermistor datasheet |
langster1980 | 6:120a0a3ff2e1 | 5 | #define resistance 10 //10k Resistor used in measurement bridge |
langster1980 | 6:120a0a3ff2e1 | 6 | |
langster1980 | 6:120a0a3ff2e1 | 7 | float tempReading = 0; // the analog reading from the sensor |
langster1980 | 6:120a0a3ff2e1 | 8 | float tempCalc = 0; // the calculated temperature |
langster1980 | 6:120a0a3ff2e1 | 9 | int rockersw_val = 0; //holds the status of the 4Dbutton0 Object |
langster1980 | 6:120a0a3ff2e1 | 10 | int flag = 0; //flag variable to store rockerswitch state |
langster1980 | 6:120a0a3ff2e1 | 11 | |
langster1980 | 6:120a0a3ff2e1 | 12 | AnalogIn tempIn(p15); // thermistor temperature sensor attached to pin 15 |
chris215 | 4:5e14a065031d | 13 | /* |
chris215 | 4:5e14a065031d | 14 | The Mbed4dGenie class requires 3 parameters |
chris215 | 4:5e14a065031d | 15 | 1 - Tx pin |
chris215 | 4:5e14a065031d | 16 | 2 - Rx pin |
chris215 | 4:5e14a065031d | 17 | 3 - Reset pin |
chris215 | 4:5e14a065031d | 18 | */ |
langster1980 | 6:120a0a3ff2e1 | 19 | Mbed4dGenie lcd4d(p9,p10,p11 ); |
langster1980 | 6:120a0a3ff2e1 | 20 | |
langster1980 | 6:120a0a3ff2e1 | 21 | void getSensorReading(void) |
langster1980 | 6:120a0a3ff2e1 | 22 | { |
langster1980 | 6:120a0a3ff2e1 | 23 | tempReading = (tempIn); // Read the sensor data from analogue pin 26 |
langster1980 | 6:120a0a3ff2e1 | 24 | tempCalc = beta / (log(((resistance / tempReading) - 10.0) / 10.0) + (beta / 298.0)) - 273.0; // Calcuate the actual temperature |
langster1980 | 6:120a0a3ff2e1 | 25 | if (tempCalc >= 130) |
langster1980 | 6:120a0a3ff2e1 | 26 | tempCalc = 130; |
langster1980 | 6:120a0a3ff2e1 | 27 | } |
chris215 | 5:b1e5af95a2fb | 28 | |
chris215 | 5:b1e5af95a2fb | 29 | void MyGenieEventHandler(void) |
chris215 | 0:f065693322dd | 30 | { |
chris215 | 5:b1e5af95a2fb | 31 | genieFrame TheEven; |
langster1980 | 6:120a0a3ff2e1 | 32 | while(lcd4d.PendingFrames()) { |
langster1980 | 6:120a0a3ff2e1 | 33 | if(lcd4d.genieDequeueEvent(&TheEven)) { |
langster1980 | 6:120a0a3ff2e1 | 34 | if( TheEven.reportObject.cmd == GENIE_REPORT_EVENT) { |
langster1980 | 6:120a0a3ff2e1 | 35 | if (TheEven.reportObject.object == GENIE_OBJ_ROCKERSW) { // If the Reported Message was from a rocker switch |
langster1980 | 6:120a0a3ff2e1 | 36 | if (TheEven.reportObject.index == 0) { |
langster1980 | 6:120a0a3ff2e1 | 37 | //printf("Rocker switch 0 pressed!\n\r"); |
langster1980 | 6:120a0a3ff2e1 | 38 | rockersw_val = lcd4d.genieGetEventData(&TheEven); //extract the MSB and LSB values and pass them to rockersw_val |
langster1980 | 6:120a0a3ff2e1 | 39 | |
langster1980 | 6:120a0a3ff2e1 | 40 | if (rockersw_val == 0) { //if Rockerswitch0 is off |
langster1980 | 6:120a0a3ff2e1 | 41 | flag = 0; |
langster1980 | 6:120a0a3ff2e1 | 42 | //printf("Rocker switch switch in off state\n\r"); //print a serial message for debugging |
langster1980 | 6:120a0a3ff2e1 | 43 | } |
langster1980 | 6:120a0a3ff2e1 | 44 | |
langster1980 | 6:120a0a3ff2e1 | 45 | else if (rockersw_val == 1) { //if Rockerswitch0 is on |
langster1980 | 6:120a0a3ff2e1 | 46 | flag = 1; |
langster1980 | 6:120a0a3ff2e1 | 47 | //printf("Rocker switch switch in ON state\n\r"); //print a serial message for debugging |
langster1980 | 6:120a0a3ff2e1 | 48 | } |
langster1980 | 6:120a0a3ff2e1 | 49 | } |
langster1980 | 6:120a0a3ff2e1 | 50 | } |
chris215 | 4:5e14a065031d | 51 | } |
chris215 | 0:f065693322dd | 52 | } |
chris215 | 5:b1e5af95a2fb | 53 | } |
chris215 | 4:5e14a065031d | 54 | } |
chris215 | 0:f065693322dd | 55 | |
langster1980 | 6:120a0a3ff2e1 | 56 | int main() |
langster1980 | 6:120a0a3ff2e1 | 57 | { |
langster1980 | 6:120a0a3ff2e1 | 58 | //int temp = 0; |
langster1980 | 6:120a0a3ff2e1 | 59 | printf("Mbed Genie demo with 10k thermistor \n\r"); |
langster1980 | 6:120a0a3ff2e1 | 60 | lcd4d.Start(); |
langster1980 | 6:120a0a3ff2e1 | 61 | |
chris215 | 5:b1e5af95a2fb | 62 | lcd4d.genieAttachEventHandler(&MyGenieEventHandler); |
langster1980 | 6:120a0a3ff2e1 | 63 | |
chris215 | 0:f065693322dd | 64 | while(1) { |
langster1980 | 6:120a0a3ff2e1 | 65 | |
langster1980 | 6:120a0a3ff2e1 | 66 | getSensorReading(); |
langster1980 | 6:120a0a3ff2e1 | 67 | |
langster1980 | 6:120a0a3ff2e1 | 68 | if (flag == 1) { |
langster1980 | 6:120a0a3ff2e1 | 69 | lcd4d.genieWriteObject(GENIE_OBJ_THERMOMETER,0x00,tempCalc); |
langster1980 | 6:120a0a3ff2e1 | 70 | |
langster1980 | 6:120a0a3ff2e1 | 71 | tempCalc = tempCalc * 100; |
langster1980 | 6:120a0a3ff2e1 | 72 | lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,0x00,tempCalc); |
chris215 | 3:4fe144f2f64e | 73 | } |
chris215 | 5:b1e5af95a2fb | 74 | |
langster1980 | 6:120a0a3ff2e1 | 75 | else if(flag == 0) |
langster1980 | 6:120a0a3ff2e1 | 76 | |
chris215 | 5:b1e5af95a2fb | 77 | { |
langster1980 | 6:120a0a3ff2e1 | 78 | lcd4d.genieWriteObject(GENIE_OBJ_THERMOMETER,0x00, 0); |
langster1980 | 6:120a0a3ff2e1 | 79 | lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,0x00, 0); |
chris215 | 5:b1e5af95a2fb | 80 | } |
langster1980 | 6:120a0a3ff2e1 | 81 | |
langster1980 | 6:120a0a3ff2e1 | 82 | |
chris215 | 0:f065693322dd | 83 | } |
langster1980 | 6:120a0a3ff2e1 | 84 | } |