A system to control fan speed according to temperature values.
Fork of Home_Monitoring_System by
main.cpp@4:bfc60dcb627a, 2018-03-20 (annotated)
- Committer:
- habusaq
- Date:
- Tue Mar 20 19:58:45 2018 +0000
- Revision:
- 4:bfc60dcb627a
- Parent:
- 3:399fd9e24cea
A system to control fan speed according to temperature values.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wmerghan | 0:4c4db81e5752 | 1 | #include "mbed.h" |
wmerghan | 0:4c4db81e5752 | 2 | |
wmerghan | 0:4c4db81e5752 | 3 | AnalogIn temp(A0); |
habusaq | 4:bfc60dcb627a | 4 | PwmOut control(D3); |
habusaq | 4:bfc60dcb627a | 5 | Serial pc(USBTX, USBRX); |
habusaq | 4:bfc60dcb627a | 6 | Serial bt(PTC17, PTC16); |
shabach | 3:399fd9e24cea | 7 | |
habusaq | 4:bfc60dcb627a | 8 | |
wmerghan | 0:4c4db81e5752 | 9 | |
wmerghan | 0:4c4db81e5752 | 10 | int main(void) |
wmerghan | 0:4c4db81e5752 | 11 | { |
habusaq | 4:bfc60dcb627a | 12 | float tempC; |
habusaq | 4:bfc60dcb627a | 13 | float tempF; |
habusaq | 4:bfc60dcb627a | 14 | int TempC; |
habusaq | 4:bfc60dcb627a | 15 | char c; |
habusaq | 4:bfc60dcb627a | 16 | |
shabach | 3:399fd9e24cea | 17 | |
wmerghan | 0:4c4db81e5752 | 18 | |
habusaq | 4:bfc60dcb627a | 19 | pc.printf("\n\nProgram Started \r\n"); |
habusaq | 4:bfc60dcb627a | 20 | |
habusaq | 4:bfc60dcb627a | 21 | //6.785503686 |
wmerghan | 0:4c4db81e5752 | 22 | |
wmerghan | 0:4c4db81e5752 | 23 | while(1) |
wmerghan | 0:4c4db81e5752 | 24 | { |
habusaq | 4:bfc60dcb627a | 25 | control.period(0.000000000000001); //10 kHz |
habusaq | 4:bfc60dcb627a | 26 | tempC = (temp*6.786*10); |
wmerghan | 0:4c4db81e5752 | 27 | tempF = (9.0*tempC)/5.0 + 32.0; |
habusaq | 4:bfc60dcb627a | 28 | TempC = tempC; |
habusaq | 4:bfc60dcb627a | 29 | if(bt.readable() > 0) |
habusaq | 4:bfc60dcb627a | 30 | c = bt.getc(); |
habusaq | 4:bfc60dcb627a | 31 | |
habusaq | 4:bfc60dcb627a | 32 | if(pc.readable()) |
habusaq | 4:bfc60dcb627a | 33 | bt.putc(pc.getc()); |
habusaq | 4:bfc60dcb627a | 34 | |
habusaq | 4:bfc60dcb627a | 35 | |
shabach | 3:399fd9e24cea | 36 | pc.printf("Temperature is %.2f C %.2f F\n\r", tempC, tempF); |
shabach | 3:399fd9e24cea | 37 | |
wmerghan | 0:4c4db81e5752 | 38 | wait(1); |
wmerghan | 0:4c4db81e5752 | 39 | |
habusaq | 4:bfc60dcb627a | 40 | |
habusaq | 4:bfc60dcb627a | 41 | if(tempC > 28 || c == 's') |
habusaq | 4:bfc60dcb627a | 42 | { |
habusaq | 4:bfc60dcb627a | 43 | control.write(0.79); |
habusaq | 4:bfc60dcb627a | 44 | DigitalOut test2(D2, 1); |
habusaq | 4:bfc60dcb627a | 45 | DigitalOut test1(D4, 0); |
habusaq | 4:bfc60dcb627a | 46 | |
habusaq | 4:bfc60dcb627a | 47 | //LED red |
habusaq | 4:bfc60dcb627a | 48 | |
habusaq | 4:bfc60dcb627a | 49 | } |
habusaq | 4:bfc60dcb627a | 50 | |
habusaq | 4:bfc60dcb627a | 51 | else if(tempC > 34 || c == 'f') |
wmerghan | 0:4c4db81e5752 | 52 | { |
habusaq | 4:bfc60dcb627a | 53 | control.write(1); |
habusaq | 4:bfc60dcb627a | 54 | DigitalOut test1(D4, 1); |
habusaq | 4:bfc60dcb627a | 55 | DigitalOut test2(D2, 0); |
habusaq | 4:bfc60dcb627a | 56 | |
habusaq | 4:bfc60dcb627a | 57 | //LED green |
habusaq | 4:bfc60dcb627a | 58 | } |
habusaq | 4:bfc60dcb627a | 59 | |
habusaq | 4:bfc60dcb627a | 60 | else //(tempC < 28 || c == 'p') |
habusaq | 4:bfc60dcb627a | 61 | { |
habusaq | 4:bfc60dcb627a | 62 | DigitalOut test1(D4, 0); |
habusaq | 4:bfc60dcb627a | 63 | DigitalOut test2(D2, 0); |
habusaq | 4:bfc60dcb627a | 64 | control.write(0); |
wmerghan | 0:4c4db81e5752 | 65 | } |
wmerghan | 0:4c4db81e5752 | 66 | |
habusaq | 4:bfc60dcb627a | 67 | |
wmerghan | 0:4c4db81e5752 | 68 | } |
wmerghan | 0:4c4db81e5752 | 69 | } |
shabach | 3:399fd9e24cea | 70 | |
shabach | 3:399fd9e24cea | 71 | |
shabach | 3:399fd9e24cea | 72 | |
shabach | 3:399fd9e24cea | 73 | |
habusaq | 4:bfc60dcb627a | 74 | |
shabach | 3:399fd9e24cea | 75 | |
shabach | 3:399fd9e24cea | 76 | |
shabach | 3:399fd9e24cea | 77 | |
shabach | 3:399fd9e24cea | 78 | |
shabach | 3:399fd9e24cea | 79 | |
shabach | 3:399fd9e24cea | 80 | |
habusaq | 4:bfc60dcb627a | 81 | |
shabach | 3:399fd9e24cea | 82 | |
habusaq | 4:bfc60dcb627a | 83 |