Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
Fork of StadiumHelper by
Diff: main.cpp
- Revision:
- 1:2f7eee3b65ee
- Parent:
- 0:0927a4a6f549
diff -r 0927a4a6f549 -r 2f7eee3b65ee main.cpp
--- a/main.cpp Sun Apr 24 21:08:37 2016 +0000
+++ b/main.cpp Sun May 01 03:50:49 2016 +0000
@@ -6,14 +6,35 @@
#include "rtos.h"
DigitalOut myled(LED1);
DigitalOut myled2(LED2);
-DigitalOut fan(p20);
+DigitalOut SSR(p20);
#include "emic2.h"
uLCD_4DGL uLCD(p28, p27, p29);
emic2 myTTS(p9, p10); //serial RX,TX pins to emic
//uLCD_4DGL uLCD(p28, p27, p29);
Serial pc(p13, p14); //this is the xbee
-Serial pc2(USBTX, USBRX); //this is a computer connected to the mbed for testing purposes
+//Serial pc(USBTX, USBRX); //this is a computer connected to the mbed for testing purposes
Mutex m;
+
+InterruptIn zerocross(p22);
+Timeout SSRtriggerOn;
+volatile float dim;
+volatile float saveDim;
+const float powerlinefrequency=60.000;
+
+void triggerOn()
+{
+ SSR = 1;
+}
+
+void dimmer()
+{
+ // turn off SSR at zero crossing
+ SSR = 0;
+ // compute time delay using dim value and set timer interrupt
+ // triggers SSR after a small post zero crossing time delay
+ SSRtriggerOn.attach(&triggerOn,(1.001 - dim)/(2*powerlinefrequency));
+}
+
class TMP36
{
public:
@@ -46,6 +67,7 @@
Erase sentence when finished with a command
Need mutex so serial communications don't interrupt each other.
*/
+ bool on = true;
while(1) {
if(pc.readable()){
m.lock();
@@ -59,10 +81,20 @@
myTTS.speakf("%s", sentence);
myTTS.ready();
sentence = "";
- } else if (letter == '*') {
- fan = !fan;
- myled = !myled;
- sentence = "";
+// } else if (letter == '*') {
+// dim = 0;
+// wait(0.5);
+// myled = !myled;
+// sentence = "";
+ } else if (letter == '#') {
+ while(!pc.readable()){
+ }
+ a = pc.getc();
+ letter = (char)a;
+ float b = (float)letter - 48;
+ dim = b * 0.1;
+ wait(.05);
+ sentence = "";
}
m.unlock();
}
@@ -71,6 +103,9 @@
}
}
int main() {
+ zerocross.mode(PullNone);
+ wait(0.2);
+ zerocross.rise(&dimmer);
Thread thread1(ttsThread);
float tempC, tempF;
int blue, red, color;
@@ -89,7 +124,7 @@
//send through xbee to pc
pc.printf("%f\n", tempC);
//send through usb for debugging
- pc2.printf("%f\n\r", tempC);
+// pc2.printf("%f\n\r", tempC);
uLCD.printf("%5.2f C \n\n%5.2f F \n\r\n", tempC, tempF);
if(tempF < 32) {
uLCD.printf("It's cold!");
