smart-home
/
smart-home-final-version
Final version of program with changed pin for PWM, freq for led and bluetooth comma seperated values
main.cpp
- Committer:
- valorad
- Date:
- 2018-09-30
- Revision:
- 2:6acc2f4efd39
- Parent:
- 0:3e6bb88dd7ee
- Child:
- 3:abe0c74fd74d
File content as of revision 2:6acc2f4efd39:
#include "mbed.h" #include "TextLCD.h" void settemp(); void tempmenu(); float getTemp(); AnalogIn temp_sen(A0); TextLCD lcd(PTC7,PTC0,PTC3,PTC4,PTC5,PTC6); InterruptIn button(D0); DigitalIn push2(D1); DigitalIn push1(D2); DigitalIn push3(D3); PwmOut mypwm(A5); //DigitalOut myled(A); int temp = 25; //float tempC, tempF, tempSamp[10]; int main() { tempmenu(); } void settemp(){ lcd.cls(); lcd.printf("enter temp: %d",temp); wait(0.2); while(1){ // temp up if(push2 == 0){ temp++; lcd.printf("enter temp: %d",temp); } // temp down if(push1 == 0){ temp--; lcd.printf("enter temp: %d",temp); } // confirm if(push3 == 0){ break; } lcd.cls(); wait(0.2); } } void tempmenu() { // interrupt button.fall(&settemp); while(1) { lcd.cls(); mypwm.period_ms(10); // display menu lcd.printf("T:%.2f \n", getTemp()); lcd.printf("1 to mod temp"); wait(0.2); if(getTemp() < temp){ // if current temp is below temp set wait(0.5); mypwm.pulsewidth_ms(8); } else { mypwm.pulsewidth_ms(2); } } } float getTemp() { float avg = 0.0; float tempC, tempF, tempSamp[10]; int i; // read temp from sensor for(i = 0; i < 10; i++) { tempSamp[i] = temp_sen.read(); wait(.05); } // calc average temp for(i = 0; i < 10; i++){ avg = avg + (tempSamp[i] / 10); } // calc result tempC = (avg * 3.685503686 * 100); tempF = (9.0 * tempC) / 5.0 + 32.0; return tempC; }