Control fan speed by temperature sensor reading. Set point can be adjusted by buttons.
Dependencies: mbed DebounceIn TextLCD DS1820
main.cpp
- Committer:
- mustafayassin
- Date:
- 2021-12-02
- Revision:
- 0:af20639f9907
- Child:
- 1:d6ceed323d25
File content as of revision 0:af20639f9907:
#include "mbed.h" #include "TextLCD.h" #include "DebounceIn.h" /* This basic example just shows how to read the ADC internal channels raw values. Please look in the corresponding device reference manual for a complete description of how to make a temperature sensor, VBat or Vref measurement. */ // Temperature input AnalogIn adc_temp1(A0); AnalogIn adc_temp2(A1); AnalogIn adc_temp3(A2); // Switch input DebounceIn tempUp(A3); DebounceIn tempDown(A4); DebounceIn onOff(A5); // LCD TextLCD lcd(D0, D1, D2, D3, D4, D5); // rs, e, d4-d7 // LED DigitalOut led(LED1); // PWM PwmOut fan(D12); uint8_t tempSetValue = 25; // degree bool fanOn = false; float fanDutyCycle = 0.0f; //const uint8_t PRESS_DURATION = 5; int main() { // Configure tempUp.mode(PullUp); tempDown.mode(PullUp); onOff.mode(PullUp); fan.period(4.0f); // period fan.write(fanDutyCycle); // duty cycle // Loop while(1) { float temp1 = (adc_temp1.read()*3.3f*100.0f); lcd.printf("Temp1 = %.1f\n", temp1); lcd.printf(""); printf("\033[2A"); if(tempUp == 0) tempSetValue++; if(tempDown == 0) tempSetValue--; if(onOff == 0) fanOn = !fanOn; //if(temp1 > tempSetValue && fanOn) { // fan.write(fanDutyCycle); //} else { // fan.write(0.0); //} led = !led; wait(0.020); } }