![](/media/cache/profiles/06833b73c7b85d172f55b6f38a40b094.jpg.50x50_q85.jpg)
a quick program to test the 4Dgenie library
Fork of Genie_Test by
Diff: main.cpp
- Revision:
- 6:120a0a3ff2e1
- Parent:
- 5:b1e5af95a2fb
--- a/main.cpp Sun Jul 06 17:24:43 2014 +0000 +++ b/main.cpp Sun Jul 06 22:17:07 2014 +0000 @@ -1,69 +1,84 @@ #include "mbed.h" #include "mbed_genie.h" -DigitalOut myled(LED1); -DigitalOut myledr(LED2); +#define beta 3977 // from the thermistor datasheet +#define resistance 10 //10k Resistor used in measurement bridge + +float tempReading = 0; // the analog reading from the sensor +float tempCalc = 0; // the calculated temperature +int rockersw_val = 0; //holds the status of the 4Dbutton0 Object +int flag = 0; //flag variable to store rockerswitch state + +AnalogIn tempIn(p15); // thermistor temperature sensor attached to pin 15 /* The Mbed4dGenie class requires 3 parameters 1 - Tx pin 2 - Rx pin 3 - Reset pin */ -Mbed4dGenie lcd4d(PTE0,PTE1,PTB9); +Mbed4dGenie lcd4d(p9,p10,p11 ); + +void getSensorReading(void) +{ + tempReading = (tempIn); // Read the sensor data from analogue pin 26 + tempCalc = beta / (log(((resistance / tempReading) - 10.0) / 10.0) + (beta / 298.0)) - 273.0; // Calcuate the actual temperature + if (tempCalc >= 130) + tempCalc = 130; +} void MyGenieEventHandler(void) { genieFrame TheEven; - while(lcd4d.PendingFrames()){ - if(lcd4d.genieDequeueEvent(&TheEven)) - { - - if( TheEven.reportObject.cmd == GENIE_REPORT_EVENT) - { - myledr = !myledr; //toggle led when receiving a genie event frame + while(lcd4d.PendingFrames()) { + if(lcd4d.genieDequeueEvent(&TheEven)) { + if( TheEven.reportObject.cmd == GENIE_REPORT_EVENT) { + if (TheEven.reportObject.object == GENIE_OBJ_ROCKERSW) { // If the Reported Message was from a rocker switch + if (TheEven.reportObject.index == 0) { + //printf("Rocker switch 0 pressed!\n\r"); + rockersw_val = lcd4d.genieGetEventData(&TheEven); //extract the MSB and LSB values and pass them to rockersw_val + + if (rockersw_val == 0) { //if Rockerswitch0 is off + flag = 0; + //printf("Rocker switch switch in off state\n\r"); //print a serial message for debugging + } + + else if (rockersw_val == 1) { //if Rockerswitch0 is on + flag = 1; + //printf("Rocker switch switch in ON state\n\r"); //print a serial message for debugging + } + } + } } - - } } } -int main() { - int temp = 0; - printf("Mbed Genie demo \n\r"); - lcd4d.Start(); +int main() +{ + //int temp = 0; + printf("Mbed Genie demo with 10k thermistor \n\r"); + lcd4d.Start(); + lcd4d.genieAttachEventHandler(&MyGenieEventHandler); - /* - for example, in this loop we increment the object from 0 to 100 - */ - + while(1) { - if(temp >= 100) - { - temp = 0; - } - else - { - temp++; + + getSensorReading(); + + if (flag == 1) { + lcd4d.genieWriteObject(GENIE_OBJ_THERMOMETER,0x00,tempCalc); + + tempCalc = tempCalc * 100; + lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,0x00,tempCalc); } - //printf("write:%d\n\r",lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,1,temp)); - int error; - error = lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,1,temp); - if(error != ERROR_NONE) + else if(flag == 0) + { - printf("Error is:%d\n\r",error); + lcd4d.genieWriteObject(GENIE_OBJ_THERMOMETER,0x00, 0); + lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,0x00, 0); } - - myled = 1; - //wait(0.05); - //printf("read:%d\n\r",lcd4d.genieReadObj(GENIE_OBJ_LED_DIGITS,1)); - error = lcd4d.genieReadObj(GENIE_OBJ_LED_DIGITS,1); - if(error != ERROR_NONE) - { - printf("Error is:%d\n\r",error); - } - myled = 0; - //wait(0.05); + + } -} +} \ No newline at end of file