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
Revision 0:0927a4a6f549, committed 2016-04-24
- Comitter:
- wongman
- Date:
- Sun Apr 24 21:08:37 2016 +0000
- Commit message:
- Final commit for 4180 final project, Stadium helper
Changed in this revision
diff -r 000000000000 -r 0927a4a6f549 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Sun Apr 24 21:08:37 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
diff -r 000000000000 -r 0927a4a6f549 emic2.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emic2.h Sun Apr 24 21:08:37 2016 +0000 @@ -0,0 +1,41 @@ +#define speakf printf +class emic2 : public Stream +{ +public : + emic2(PinName tx, PinName rx): _cmd(tx,rx) { + _cmd.baud(9600); + _cmd.putc('X'); //stop talking if reset and not a power on + _cmd.putc('\r'); // Send a CR in case the system is already up + wait(1); //delay for emic power on boot or reset respone + while (_cmd.getc() != ':'); // When the Emic 2 has initialized and is ready, it will send a single ':' + while (_cmd.readable()) _cmd.getc();//flush out buffer just in case + }; + void ready() { + while (_cmd.getc() != ':'); + while (_cmd.readable()) _cmd.getc();//flush out recieve buffer just in case + }; + int readable() { + return _cmd.readable(); + }; + int getc() { + return _cmd.getc(); + } + void volume(int x) { + speakf("V%D\r",x); + ready(); + } + void voice(int x) { + speakf("N%D\r",x); + ready(); + } +protected : + Serial _cmd; + //used by printf - supply it and printf works! + virtual int _putc(int c) { + _cmd.putc(c); + return 0; + }; + virtual int _getc() { + return -1; + }; +};
diff -r 000000000000 -r 0927a4a6f549 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Apr 24 21:08:37 2016 +0000 @@ -0,0 +1,108 @@ +#include "mbed.h" +#include "uLCD_4DGL.h" +#include <iostream> +#include <stdio.h> +#include <stdlib.h> +#include "rtos.h" +DigitalOut myled(LED1); +DigitalOut myled2(LED2); +DigitalOut fan(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 +Mutex m; +class TMP36 +{ +public: +TMP36(PinName pin); +TMP36(); +float read(); +private: +//class sets up the AnalogIn pin +AnalogIn _pin; +}; +TMP36::TMP36(PinName pin) : _pin(pin) {} //This is an initializer list … more to come in class +// _pin(pin) means pass pin to the AnalogIn constructor +float TMP36::read() +{ +//convert sensor reading to temperature in degrees C +return ((_pin.read()*3.3)-0.500)*100.0; +} +TMP36 myTMP36(p15); + +void ttsThread(void const *args) { + printf("starting up\n\r"); + myTTS.volume(18); //max volume + string sentence; + char letter; + /* + Whlie there is stuff in the buffer, continue to take characters out of the buffer + and append it to the char array sentence + When hit with a punctuation, send to TTS module + If we see an *, which is sent by the toggle button, toggle the lamp. + Erase sentence when finished with a command + Need mutex so serial communications don't interrupt each other. + */ + while(1) { + if(pc.readable()){ + m.lock(); + myled2 = 1; + int a = pc.getc(); + myled2 = 0; + letter = (char)a; + sentence = sentence + letter; + if(letter == '!' || letter == '.' || letter == '?') { + sentence = "S" + sentence + "\r"; + myTTS.speakf("%s", sentence); + myTTS.ready(); + sentence = ""; + } else if (letter == '*') { + fan = !fan; + myled = !myled; + sentence = ""; + } + m.unlock(); + } + + Thread::wait(1); + } +} +int main() { + Thread thread1(ttsThread); + float tempC, tempF; + int blue, red, color; + while(1) { + tempC = myTMP36.read(); //convert to degrees F + tempF = (9.0*tempC)/5.0 + 32.0; //print current temp + uLCD.cls(); + red = (tempF) * 2.55; + (red <= 0 ? red = 0 : red = red); + (red >= 255 ? red = 255 : red = red); + blue = 255 - red; + red = red << 16; + color = red + blue; + uLCD.color(color); + m.lock(); + //send through xbee to pc + pc.printf("%f\n", tempC); + //send through usb for debugging + 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!"); + } else if (tempF < 50) { + uLCD.printf("It's a little\nchilly!"); + } else if (tempF < 70) { + uLCD.printf("It's not bad out,\nenjoy the day!"); + } else if (tempF < 85) { + uLCD.printf("Ahh room\ntemperature!"); + } else { + uLCD.printf("It's pretty hot!"); + } + m.unlock(); + Thread::wait(500); + } +} \ No newline at end of file
diff -r 000000000000 -r 0927a4a6f549 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sun Apr 24 21:08:37 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#bdd541595fc5
diff -r 000000000000 -r 0927a4a6f549 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Apr 24 21:08:37 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f \ No newline at end of file