
VSD
Dependencies: 4DGL-uLCD-SE HTU21D mbed-rtos mbed wave_player
Revision 12:a5be4d71addc, committed 2022-12-09
- Comitter:
- dajbaptis
- Date:
- Fri Dec 09 04:25:45 2022 +0000
- Parent:
- 11:0309bef74ba8
- Commit message:
- ece 4180 project
Changed in this revision
diff -r 0309bef74ba8 -r a5be4d71addc 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Fri Dec 09 04:25:45 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
diff -r 0309bef74ba8 -r a5be4d71addc HTU21D.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTU21D.lib Fri Dec 09 04:25:45 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/alipford3/code/HTU21D/#4fd07be6bad8
diff -r 0309bef74ba8 -r a5be4d71addc SongPlayer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SongPlayer.h Fri Dec 09 04:25:45 2022 +0000 @@ -0,0 +1,41 @@ +#include "mbed.h" +// new class to play a note on Speaker based on PwmOut class +class SongPlayer +{ +public: + SongPlayer(PinName pin) : _pin(pin) { +// _pin(pin) means pass pin to the constructor + } +// class method to play a note based on PwmOut class + void PlaySong(float frequency[], float duration[], float volume=1.0) { + vol = volume; + notecount = 0; + _pin.period(1.0/frequency[notecount]); + _pin = volume/2.0; + noteduration.attach(this,&SongPlayer::nextnote, duration[notecount]); + // setup timer to interrupt for next note to play + frequencyptr = frequency; + durationptr = duration; + //returns after first note starts to play + } + void nextnote(); +private: + Timeout noteduration; + PwmOut _pin; + int notecount; + float vol; + float * frequencyptr; + float * durationptr; +}; +//Interrupt Routine to play next note +void SongPlayer::nextnote() +{ + _pin = 0.0; + notecount++; //setup next note in song + if (durationptr[notecount]!=0.0) { + _pin.period(1.0/frequencyptr[notecount]); + noteduration.attach(this,&SongPlayer::nextnote, durationptr[notecount]); + _pin = vol/2.0; + } else + _pin = 0.0; //turn off on last note +} \ No newline at end of file
diff -r 0309bef74ba8 -r a5be4d71addc main.cpp --- a/main.cpp Wed Feb 15 14:04:02 2017 -0600 +++ b/main.cpp Fri Dec 09 04:25:45 2022 +0000 @@ -1,22 +1,111 @@ +/** Sample program to read temperature and humidity + * + * @author Alex Lipford + * Georgia Institute of Technology + * ECE 4180 Embeded Systems Design + * Professor Hamblen + * 10/19/2014 + * + * @section LICENSE + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * <alexlipford@gmail.com> wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. + * ---------------------------------------------------------------------------- + * + * + * @section DESCRIPTION + * + * Honeywell HTU21D Humidity and Temperature sensor. + * + * Datasheet, specs, and information: + * + * https://www.sparkfun.com/products/12064 + */ + #include "mbed.h" +#include <string> +#include <stdlib.h> +#include "HTU21D.h" +#include "uLCD_4DGL.h" +#include "SongPlayer.h" +#include <math.h> #include "rtos.h" - + +Serial pc(USBTX, USBRX); + +DigitalOut reset(p26); DigitalOut led1(LED1); -DigitalOut led2(LED2); -Thread thread; +DigitalOut led4(LED4); +Timer t; + +AnalogIn CO2(p18); +uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin; +HTU21D temphumid(p9, p10); //Temp humid sensor || SDA, SCL +int sample_ftemp; +int sample_ctemp; +int sample_humid; +float sample_co2; + +float note[7]= {700.0,0,700.0,0,700.0,0,700.0 + }; +float duration[7]= {0.48,0.48,0.48,0.48,0.48,0.48, 0.0 + }; + + -void led2_thread() { - while (true) { - led2 = !led2; +void sensorsthread(void const *args) { + while (1) { + sample_ftemp = temphumid.sample_ftemp(); + sample_ctemp = temphumid.sample_ctemp(); + sample_humid = temphumid.sample_humid(); + sample_co2 = CO2.read()*1000; + Thread::wait(1000); + } +} + + +void lcdthread(void const *args) { + uLCD.background_color(BLACK); + uLCD.cls(); + uLCD.baudrate(30000); //jack up baud rate to max for fast display + + while (1) { + uLCD.cls(); + uLCD.locate(0,2); + uLCD.color(WHITE); + uLCD.printf("Temperature: %d F\n\r", sample_ftemp); + uLCD.printf("Temperature: %d C\n\r", sample_ctemp); + uLCD.printf("Humidity: %d %%\n\r", sample_humid); + uLCD.printf("Gas: %0.2f ppm \n\r", sample_co2); + if (sample_co2 > 80){ uLCD.printf("Evacuate! CO is high!");} + uLCD.printf("\n\r"); + wait(0.5); + Thread::wait(1000); } } - + int main() { - thread.start(led2_thread); - - while (true) { - led1 = !led1; - Thread::wait(500); + + sample_ftemp = temphumid.sample_ftemp(); + sample_ctemp = temphumid.sample_ctemp(); + sample_humid = temphumid.sample_humid(); + + pc.printf("Begin Thread\n"); + Thread t1(sensorsthread); + Thread t3(lcdthread); + + SongPlayer mySpeaker(p26); + + + while(1) { + if (sample_co2 > 80) { + mySpeaker.PlaySong(note,duration); + } + + Thread::wait(1000); } } +
diff -r 0309bef74ba8 -r a5be4d71addc mbed-rtos.lib --- a/mbed-rtos.lib Wed Feb 15 14:04:02 2017 -0600 +++ b/mbed-rtos.lib Fri Dec 09 04:25:45 2022 +0000 @@ -1,1 +1,1 @@ -https://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e +https://os.mbed.com/users/mbed_official/code/mbed-rtos/#5713cbbdb706
diff -r 0309bef74ba8 -r a5be4d71addc mbed.bld --- a/mbed.bld Wed Feb 15 14:04:02 2017 -0600 +++ b/mbed.bld Fri Dec 09 04:25:45 2022 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file
diff -r 0309bef74ba8 -r a5be4d71addc wave_player.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Fri Dec 09 04:25:45 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/sravet/code/wave_player/#acc3e18e77ad