Karlo Šestak
/
regulator_napona
LCD Hello mbed World!
main.cpp@1:b501f964e376, 2020-06-19 (annotated)
- Committer:
- ksestak
- Date:
- Fri Jun 19 15:55:05 2020 +0000
- Revision:
- 1:b501f964e376
- Parent:
- 0:0a5c73c2369a
Regulacija napona potenciometrom
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takeuchi | 0:0a5c73c2369a | 1 | #include "mbed.h" |
takeuchi | 0:0a5c73c2369a | 2 | #include "TextLCD.h" |
takeuchi | 0:0a5c73c2369a | 3 | |
takeuchi | 0:0a5c73c2369a | 4 | TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d4, d5, d6, d7 |
ksestak | 1:b501f964e376 | 5 | AnalogIn Ain(p17); |
ksestak | 1:b501f964e376 | 6 | DigitalOut ledica1(LED1); |
ksestak | 1:b501f964e376 | 7 | float napon; |
ksestak | 1:b501f964e376 | 8 | InterruptIn button(p5); //define and name the interrupt input |
ksestak | 1:b501f964e376 | 9 | DigitalOut led(LED3); |
ksestak | 1:b501f964e376 | 10 | DigitalOut flash(LED4); |
ksestak | 1:b501f964e376 | 11 | |
ksestak | 1:b501f964e376 | 12 | void led_switch(void); |
ksestak | 1:b501f964e376 | 13 | Ticker time_up; //define a Ticker, with name “time_up” |
ksestak | 1:b501f964e376 | 14 | DigitalOut myled(LED2); |
ksestak | 1:b501f964e376 | 15 | void led_switch(){ //the function that Ticker will call |
ksestak | 1:b501f964e376 | 16 | myled=!myled; |
ksestak | 1:b501f964e376 | 17 | } |
ksestak | 1:b501f964e376 | 18 | |
ksestak | 1:b501f964e376 | 19 | |
ksestak | 1:b501f964e376 | 20 | void ISR1() { //this is the response to interrupt, i.e. the ISR |
ksestak | 1:b501f964e376 | 21 | led = !led; |
ksestak | 1:b501f964e376 | 22 | } |
ksestak | 1:b501f964e376 | 23 | |
ksestak | 1:b501f964e376 | 24 | int moja_funkcija(float napon){ |
ksestak | 1:b501f964e376 | 25 | if(napon > 2){ |
ksestak | 1:b501f964e376 | 26 | ledica1 = 1; |
ksestak | 1:b501f964e376 | 27 | } |
ksestak | 1:b501f964e376 | 28 | else{ |
ksestak | 1:b501f964e376 | 29 | ledica1 = 0; |
ksestak | 1:b501f964e376 | 30 | } |
ksestak | 1:b501f964e376 | 31 | return ledica1; |
ksestak | 1:b501f964e376 | 32 | } |
takeuchi | 0:0a5c73c2369a | 33 | |
takeuchi | 0:0a5c73c2369a | 34 | int main() { |
ksestak | 1:b501f964e376 | 35 | button.rise(&ISR1); |
ksestak | 1:b501f964e376 | 36 | while(1){ |
ksestak | 1:b501f964e376 | 37 | napon=Ain*3.3; |
ksestak | 1:b501f964e376 | 38 | lcd.printf("%4.2f V",napon); |
ksestak | 1:b501f964e376 | 39 | moja_funkcija(napon); |
ksestak | 1:b501f964e376 | 40 | wait(0.002); |
ksestak | 1:b501f964e376 | 41 | lcd.cls(); |
ksestak | 1:b501f964e376 | 42 | flash = !flash; |
ksestak | 1:b501f964e376 | 43 | wait(0.25); |
ksestak | 1:b501f964e376 | 44 | time_up.attach(&led_switch, 0.5); |
ksestak | 1:b501f964e376 | 45 | |
ksestak | 1:b501f964e376 | 46 | } |
ksestak | 1:b501f964e376 | 47 | } |
ksestak | 1:b501f964e376 | 48 | |
ksestak | 1:b501f964e376 | 49 | //TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d4, d5, d6, d7 |
ksestak | 1:b501f964e376 | 50 |