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
main.cpp
00001 #include "mbed.h" 00002 #include "uLCD_4DGL.h" 00003 #include <iostream> 00004 #include <stdio.h> 00005 #include <stdlib.h> 00006 #include "rtos.h" 00007 DigitalOut myled(LED1); 00008 DigitalOut myled2(LED2); 00009 DigitalOut SSR(p20); 00010 #include "emic2.h" 00011 uLCD_4DGL uLCD(p28, p27, p29); 00012 emic2 myTTS(p9, p10); //serial RX,TX pins to emic 00013 //uLCD_4DGL uLCD(p28, p27, p29); 00014 Serial pc(p13, p14); //this is the xbee 00015 //Serial pc(USBTX, USBRX); //this is a computer connected to the mbed for testing purposes 00016 Mutex m; 00017 00018 InterruptIn zerocross(p22); 00019 Timeout SSRtriggerOn; 00020 volatile float dim; 00021 volatile float saveDim; 00022 const float powerlinefrequency=60.000; 00023 00024 void triggerOn() 00025 { 00026 SSR = 1; 00027 } 00028 00029 void dimmer() 00030 { 00031 // turn off SSR at zero crossing 00032 SSR = 0; 00033 // compute time delay using dim value and set timer interrupt 00034 // triggers SSR after a small post zero crossing time delay 00035 SSRtriggerOn.attach(&triggerOn,(1.001 - dim)/(2*powerlinefrequency)); 00036 } 00037 00038 class TMP36 00039 { 00040 public: 00041 TMP36(PinName pin); 00042 TMP36(); 00043 float read(); 00044 private: 00045 //class sets up the AnalogIn pin 00046 AnalogIn _pin; 00047 }; 00048 TMP36::TMP36(PinName pin) : _pin(pin) {} //This is an initializer list … more to come in class 00049 // _pin(pin) means pass pin to the AnalogIn constructor 00050 float TMP36::read() 00051 { 00052 //convert sensor reading to temperature in degrees C 00053 return ((_pin.read()*3.3)-0.500)*100.0; 00054 } 00055 TMP36 myTMP36(p15); 00056 00057 void ttsThread(void const *args) { 00058 printf("starting up\n\r"); 00059 myTTS.volume(18); //max volume 00060 string sentence; 00061 char letter; 00062 /* 00063 Whlie there is stuff in the buffer, continue to take characters out of the buffer 00064 and append it to the char array sentence 00065 When hit with a punctuation, send to TTS module 00066 If we see an *, which is sent by the toggle button, toggle the lamp. 00067 Erase sentence when finished with a command 00068 Need mutex so serial communications don't interrupt each other. 00069 */ 00070 bool on = true; 00071 while(1) { 00072 if(pc.readable()){ 00073 m.lock(); 00074 myled2 = 1; 00075 int a = pc.getc(); 00076 myled2 = 0; 00077 letter = (char)a; 00078 sentence = sentence + letter; 00079 if(letter == '!' || letter == '.' || letter == '?') { 00080 sentence = "S" + sentence + "\r"; 00081 myTTS.speakf("%s", sentence); 00082 myTTS.ready(); 00083 sentence = ""; 00084 // } else if (letter == '*') { 00085 // dim = 0; 00086 // wait(0.5); 00087 // myled = !myled; 00088 // sentence = ""; 00089 } else if (letter == '#') { 00090 while(!pc.readable()){ 00091 } 00092 a = pc.getc(); 00093 letter = (char)a; 00094 float b = (float)letter - 48; 00095 dim = b * 0.1; 00096 wait(.05); 00097 sentence = ""; 00098 } 00099 m.unlock(); 00100 } 00101 00102 Thread::wait(1); 00103 } 00104 } 00105 int main() { 00106 zerocross.mode(PullNone); 00107 wait(0.2); 00108 zerocross.rise(&dimmer); 00109 Thread thread1(ttsThread); 00110 float tempC, tempF; 00111 int blue, red, color; 00112 while(1) { 00113 tempC = myTMP36.read(); //convert to degrees F 00114 tempF = (9.0*tempC)/5.0 + 32.0; //print current temp 00115 uLCD.cls(); 00116 red = (tempF) * 2.55; 00117 (red <= 0 ? red = 0 : red = red); 00118 (red >= 255 ? red = 255 : red = red); 00119 blue = 255 - red; 00120 red = red << 16; 00121 color = red + blue; 00122 uLCD.color(color); 00123 m.lock(); 00124 //send through xbee to pc 00125 pc.printf("%f\n", tempC); 00126 //send through usb for debugging 00127 // pc2.printf("%f\n\r", tempC); 00128 uLCD.printf("%5.2f C \n\n%5.2f F \n\r\n", tempC, tempF); 00129 if(tempF < 32) { 00130 uLCD.printf("It's cold!"); 00131 } else if (tempF < 50) { 00132 uLCD.printf("It's a little\nchilly!"); 00133 } else if (tempF < 70) { 00134 uLCD.printf("It's not bad out,\nenjoy the day!"); 00135 } else if (tempF < 85) { 00136 uLCD.printf("Ahh room\ntemperature!"); 00137 } else { 00138 uLCD.printf("It's pretty hot!"); 00139 } 00140 m.unlock(); 00141 Thread::wait(500); 00142 } 00143 }
Generated on Wed Jul 20 2022 02:32:35 by
1.7.2
