James Hughes JRH52
Dependencies: C12832 FXOS8700Q Fader LM75B MMA7660 mbed reScale
Smart Thermometer + Spirit Level for the FRDMK64F Device
This program displays the temperature in Celsius and Fahrenheit and allows the user to set a "temperature alarm" that activates once the the temperature exceeds a temperature value specified by the user.
This program also displays graphical "spirit levels" showing degrees of rotaion along 3 axis.
The user can cycle between screens using sw2 and sw3 buttons, set the temperature alarm by pressing up and down on the joystick, control the volume of the alarm with the pot1 knob, and control the time value of the wait function by pressing left and right on the joystick.
Revision 0:55c7a177fdbb, committed 2016-02-25
- Comitter:
- co838_jrh52
- Date:
- Thu Feb 25 14:25:47 2016 +0000
- Child:
- 1:829f4ff1fd05
- Commit message:
- This isn't the final version. I'm just testing if this works.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832.lib Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FXOS8700Q.lib Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Fader.lib Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ethanharstad/code/Fader/#127c030fa3ca
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LM75B.lib Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/neilt6/code/LM75B/#7ac462ba84ac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA7660.lib Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MMA7660/#36a163511e34
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,231 @@ +#include "mbed.h" +#include "LM75B.h" +#include "C12832.h" +#include "MMA7660.h" /* for the accelerometer */ +#include "reScale.h" + +DigitalOut r_led (LED1); /* connections for RGB LED */ +DigitalOut g_led (LED2); +DigitalOut b_led (LED3); + +PwmOut spkr(D6); /* speaker */ + +//DigitalOut led(LED1); /* shield LEDs */ +DigitalOut green(D5); +DigitalOut blue(PTC12); +DigitalOut red(D9); + +InterruptIn sw2_int (PTC6); /* interrupts for on-board switches */ +InterruptIn sw3_int (PTA4); +InterruptIn joy_up (PTB10); +InterruptIn joy_down (PTB11); +InterruptIn joy_left (PTC11); +InterruptIn joy_right (PTC10); +InterruptIn joy_fire (PTB23); + +AnalogIn pot1 (A0); +AnalogIn pot2 (A1); + +static volatile int sw2_trig; /* switches triggered? */ +static volatile int sw3_trig; +static volatile int joy_up_trig; +static volatile int joy_down_trig; + +void sw2_interrupt (void) +{ + sw2_trig = 1; +} + +void sw3_interrupt (void) +{ + sw3_trig = 1; +} + +void joy_up_interrupt (void) +{ + joy_up_trig = 1; +} + +void joy_down_interrupt (void) +{ + joy_down_trig = 1; +} + +// Using Arduino pin notation +C12832 lcd(D11, D13, D12, D7, D10); +LM75B sensor(D14,D15); +MMA7660 MMA(D14, D15); /* accelerometer */ + +int main () +{ + double waitTime = 0.5; + int menu = 0; + int maxTemp = 30; + double fahrenheit; + double tempC = sensor.temp(); + + sw2_trig = 0; + sw3_trig = 0; + joy_up_trig = 0; + joy_down_trig = 0; + + sw2_int.mode (PullUp); + sw2_int.fall (&sw2_interrupt); + + sw3_int.mode (PullUp); + sw3_int.fall (&sw3_interrupt); + + joy_up.mode (PullUp); + joy_up.fall (&joy_up_interrupt); + + joy_down.mode (PullUp); + joy_down.fall (&joy_down_interrupt); + + //fahrenheit = 9.00 / 5.00 * tempC + 32; + //double fahrenheitPartOne = sensor.temp() * 1.8; + //double fahrenheitPartTwo = fahrenheitPartOne + 32; + + void tempAlarm(); + void noAlarm(); + void flash(); + void thermomCel(int n, int maxTemp); + + while (1) { + + double tempDouble = static_cast<double>(sensor.temp()); + double fahrenheitPartOne = tempDouble * 1.8; + double fahrenheitPartTwo = fahrenheitPartOne + 32; + int n = static_cast<int>(sensor.temp()); + + flash(); + + if(sensor.temp()<maxTemp) { + spkr=0; + green = 7 & 4; + blue = 0 & 0; + red = 0 & 0; + } + + if(sensor.temp()< maxTemp && sensor.temp()> maxTemp - 2){ + green = 0 & 0; + blue = 7 & 4; + red = 0 & 0; + } + + if(sensor.temp()>maxTemp) { + tempAlarm(); + } + + if(menu==0) { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("Max Temp Alarm: %.1d", maxTemp); + thermomCel(n, maxTemp); + wait(waitTime); + } + + if(menu==1) { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("Celsius: %.1f\n", sensor.temp()); + thermomCel(n, maxTemp); + wait(waitTime); + } + + if(menu==2) { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("Fahrenheit: %.1lf\n",fahrenheitPartTwo); //changed this to double + thermomCel(n, maxTemp); + wait(waitTime); + } + + if(menu==3) { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", MMA.x(), MMA.y(), MMA.z()); + wait(waitTime); + } + + if(menu==4) { + lcd.cls(); + lcd.locate(0,3); + lcd.printf("%.1d", n); + wait(waitTime); + } + + + if (sw2_trig) { + menu++; + if(menu>4){ + menu = 4; + } + sw2_trig = 0; + } + + if (sw3_trig) { + menu--; + if(menu<0) { + menu = 0; + } + sw3_trig = 0; + } + + if(joy_up_trig) { + maxTemp = maxTemp + 1; + //set max value in here + joy_up_trig = 0; + } + + if(joy_down_trig) { + maxTemp = maxTemp - 1; + //set min value in here + joy_down_trig = 0; + } + + } + +} + +void tempAlarm() +{ + float volume = pot1; + + for (float i=2000.0; i<5000.0; i+=100) { + spkr.period(5.0/i); + spkr=volume; + wait(0.01); + } + + green = 0; + blue = 1; + red = 1; +} + +void noAlarm() +{ + spkr=0; + green = 1; + blue = 0; + red = 1; +} + +void flash() +{ + r_led = 0; + g_led = 1; + b_led = 1; + //b_led = !b_led; + //wait(1.00); +} + +void thermomCel(int n, int maxTemp) +{ + lcd.rect(0, 25, 120, 30, 50); + lcd.fillrect(60, 25, 60 + n, 30, 50); + lcd.circle(60, 19, 2, 50); + lcd.line(60, 25, 60, 23, 50); + lcd.line(60 + n, 25, 60 + n, 20, 50); + lcd.line(60 + maxTemp, 25, 60 + maxTemp, 20, 50); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/reScale.lib Thu Feb 25 14:25:47 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/c0ax/code/reScale/#ebb951147122