![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Coffeemaker controller
main.cpp@0:17c5e4f9a805, 2020-09-26 (annotated)
- Committer:
- jvfausto
- Date:
- Sat Sep 26 00:30:09 2020 +0000
- Revision:
- 0:17c5e4f9a805
Coffeemaker code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jvfausto | 0:17c5e4f9a805 | 1 | #include "mbed.h" |
jvfausto | 0:17c5e4f9a805 | 2 | #include "DS1820.h" |
jvfausto | 0:17c5e4f9a805 | 3 | |
jvfausto | 0:17c5e4f9a805 | 4 | PwmOut coolerAndFans(D4); |
jvfausto | 0:17c5e4f9a805 | 5 | PwmOut coolerAndPump(D5); |
jvfausto | 0:17c5e4f9a805 | 6 | PwmOut radiator(D3); |
jvfausto | 0:17c5e4f9a805 | 7 | PwmOut coffeeMaker(PA_0); |
jvfausto | 0:17c5e4f9a805 | 8 | |
jvfausto | 0:17c5e4f9a805 | 9 | DigitalOut myled(LED1); |
jvfausto | 0:17c5e4f9a805 | 10 | DigitalIn isOn(D6); |
jvfausto | 0:17c5e4f9a805 | 11 | |
jvfausto | 0:17c5e4f9a805 | 12 | int main() { |
jvfausto | 0:17c5e4f9a805 | 13 | DS1820 ds1820(D2); // substitute D8 with actual mbed pin name connected to the DS1820 data pin |
jvfausto | 0:17c5e4f9a805 | 14 | ds1820.begin(); |
jvfausto | 0:17c5e4f9a805 | 15 | bool wentDown = false; |
jvfausto | 0:17c5e4f9a805 | 16 | float temperature; |
jvfausto | 0:17c5e4f9a805 | 17 | radiator.period_ms(10); |
jvfausto | 0:17c5e4f9a805 | 18 | radiator.pulsewidth_ms(1); |
jvfausto | 0:17c5e4f9a805 | 19 | coolerAndFans.period_ms(10); |
jvfausto | 0:17c5e4f9a805 | 20 | coolerAndFans.pulsewidth_ms(1); |
jvfausto | 0:17c5e4f9a805 | 21 | coolerAndPump.period_ms(10); |
jvfausto | 0:17c5e4f9a805 | 22 | coolerAndPump.pulsewidth_ms(1); |
jvfausto | 0:17c5e4f9a805 | 23 | coffeeMaker.period_ms(10); |
jvfausto | 0:17c5e4f9a805 | 24 | coffeeMaker.pulsewidth_ms(1); |
jvfausto | 0:17c5e4f9a805 | 25 | |
jvfausto | 0:17c5e4f9a805 | 26 | while(1) { |
jvfausto | 0:17c5e4f9a805 | 27 | myled = !myled; |
jvfausto | 0:17c5e4f9a805 | 28 | printf("temperature is %3.1f, and read is %d\n", ds1820.read(), isOn.read()); |
jvfausto | 0:17c5e4f9a805 | 29 | temperature = ds1820.read(); |
jvfausto | 0:17c5e4f9a805 | 30 | |
jvfausto | 0:17c5e4f9a805 | 31 | if(temperature >= 2 && wentDown) |
jvfausto | 0:17c5e4f9a805 | 32 | wentDown = false; |
jvfausto | 0:17c5e4f9a805 | 33 | |
jvfausto | 0:17c5e4f9a805 | 34 | if(isOn.read()){ |
jvfausto | 0:17c5e4f9a805 | 35 | coolerAndFans.write(1); |
jvfausto | 0:17c5e4f9a805 | 36 | coolerAndPump.write(1); |
jvfausto | 0:17c5e4f9a805 | 37 | radiator.write(1); |
jvfausto | 0:17c5e4f9a805 | 38 | coffeeMaker.write(1); |
jvfausto | 0:17c5e4f9a805 | 39 | wait(1*60*7); |
jvfausto | 0:17c5e4f9a805 | 40 | } |
jvfausto | 0:17c5e4f9a805 | 41 | else{ |
jvfausto | 0:17c5e4f9a805 | 42 | radiator.write(0); |
jvfausto | 0:17c5e4f9a805 | 43 | coffeeMaker.write(0); |
jvfausto | 0:17c5e4f9a805 | 44 | if(temperature >= 0 && !wentDown) |
jvfausto | 0:17c5e4f9a805 | 45 | { |
jvfausto | 0:17c5e4f9a805 | 46 | coolerAndPump.write(1); |
jvfausto | 0:17c5e4f9a805 | 47 | coolerAndFans.write(1); |
jvfausto | 0:17c5e4f9a805 | 48 | } |
jvfausto | 0:17c5e4f9a805 | 49 | else{ |
jvfausto | 0:17c5e4f9a805 | 50 | wentDown = true; |
jvfausto | 0:17c5e4f9a805 | 51 | coolerAndPump.write(0); |
jvfausto | 0:17c5e4f9a805 | 52 | coolerAndFans.write(0); |
jvfausto | 0:17c5e4f9a805 | 53 | } |
jvfausto | 0:17c5e4f9a805 | 54 | radiator.write(0); |
jvfausto | 0:17c5e4f9a805 | 55 | coffeeMaker.write(0); |
jvfausto | 0:17c5e4f9a805 | 56 | } |
jvfausto | 0:17c5e4f9a805 | 57 | ds1820.startConversion(); // start temperature conversion |
jvfausto | 0:17c5e4f9a805 | 58 | |
jvfausto | 0:17c5e4f9a805 | 59 | wait(1); |
jvfausto | 0:17c5e4f9a805 | 60 | } |
jvfausto | 0:17c5e4f9a805 | 61 | } |