Brendan Leech
/
ThermoCoupleProjectOk
main.cpp@0:ae4dd2da243d, 2020-07-30 (annotated)
- Committer:
- brendanmleech
- Date:
- Thu Jul 30 18:18:42 2020 +0000
- Revision:
- 0:ae4dd2da243d
ThermoCouple BrendanL t00050766
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brendanmleech | 0:ae4dd2da243d | 1 | |
brendanmleech | 0:ae4dd2da243d | 2 | #include "mbed.h" |
brendanmleech | 0:ae4dd2da243d | 3 | #include "C12832_lcd.h" |
brendanmleech | 0:ae4dd2da243d | 4 | |
brendanmleech | 0:ae4dd2da243d | 5 | AnalogIn ain(p19); // ain is an object of class Analogin |
brendanmleech | 0:ae4dd2da243d | 6 | DigitalOut led(LED1); // led is an object if class Digitalout |
brendanmleech | 0:ae4dd2da243d | 7 | C12832_LCD lcd; // LCD is an object of class C12832 |
brendanmleech | 0:ae4dd2da243d | 8 | float temperature; |
brendanmleech | 0:ae4dd2da243d | 9 | InterruptIn joystickcenter(p14); |
brendanmleech | 0:ae4dd2da243d | 10 | InterruptIn button(p9); |
brendanmleech | 0:ae4dd2da243d | 11 | Timer debounce; |
brendanmleech | 0:ae4dd2da243d | 12 | int i; |
brendanmleech | 0:ae4dd2da243d | 13 | int x; |
brendanmleech | 0:ae4dd2da243d | 14 | |
brendanmleech | 0:ae4dd2da243d | 15 | void flip() { |
brendanmleech | 0:ae4dd2da243d | 16 | led = !led; // toggles the led when the joystick button is pressed. |
brendanmleech | 0:ae4dd2da243d | 17 | if (debounce.read_ms() > 1000 ) |
brendanmleech | 0:ae4dd2da243d | 18 | x = 1; |
brendanmleech | 0:ae4dd2da243d | 19 | debounce.reset(); |
brendanmleech | 0:ae4dd2da243d | 20 | } |
brendanmleech | 0:ae4dd2da243d | 21 | |
brendanmleech | 0:ae4dd2da243d | 22 | int main() { |
brendanmleech | 0:ae4dd2da243d | 23 | temperature = ain*600-200; |
brendanmleech | 0:ae4dd2da243d | 24 | lcd.locate(0,0); |
brendanmleech | 0:ae4dd2da243d | 25 | lcd.printf("Temperature needs reset"); |
brendanmleech | 0:ae4dd2da243d | 26 | |
brendanmleech | 0:ae4dd2da243d | 27 | if(temperature > 295) { |
brendanmleech | 0:ae4dd2da243d | 28 | for (i=0;i<60;i++); |
brendanmleech | 0:ae4dd2da243d | 29 | led=1; |
brendanmleech | 0:ae4dd2da243d | 30 | wait(0.5); |
brendanmleech | 0:ae4dd2da243d | 31 | x=1; |
brendanmleech | 0:ae4dd2da243d | 32 | { |
brendanmleech | 0:ae4dd2da243d | 33 | wait(0.5); // wait for a half a second |
brendanmleech | 0:ae4dd2da243d | 34 | |
brendanmleech | 0:ae4dd2da243d | 35 | joystickcenter.rise(&flip); // attach the function address to the rising edge |
brendanmleech | 0:ae4dd2da243d | 36 | button.mode(PullUp); // With this, no external pullup resistor needed |
brendanmleech | 0:ae4dd2da243d | 37 | button.rise(&flip); // attach the function address to the rising edge |
brendanmleech | 0:ae4dd2da243d | 38 | |
brendanmleech | 0:ae4dd2da243d | 39 | while(1) { // wait around, interrupts will interrupt this! |
brendanmleech | 0:ae4dd2da243d | 40 | if(x==1){ // set x to 1 in flip() and compare it to 1 (i.e. if x ==1 { ... } ) |
brendanmleech | 0:ae4dd2da243d | 41 | |
brendanmleech | 0:ae4dd2da243d | 42 | |
brendanmleech | 0:ae4dd2da243d | 43 | } |
brendanmleech | 0:ae4dd2da243d | 44 | } |
brendanmleech | 0:ae4dd2da243d | 45 | } |
brendanmleech | 0:ae4dd2da243d | 46 | } |
brendanmleech | 0:ae4dd2da243d | 47 | } |