Ispis na tri 7-segmentna display-a
Dependencies: mbed trostrukiSedamSeg
https://os.mbed.com/media/uploads/mmaretic/prototip_volana_formule_1.pdf
main.cpp@0:1e6d734c8f95, 2021-12-02 (annotated)
- Committer:
- mmaretic
- Date:
- Thu Dec 02 18:41:30 2021 +0000
- Revision:
- 0:1e6d734c8f95
- Child:
- 2:3227eef26c80
Finalna Verzija;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mmaretic | 0:1e6d734c8f95 | 1 | #include "mbed.h" |
mmaretic | 0:1e6d734c8f95 | 2 | #include "trostrukiSedamSeg.h" |
mmaretic | 0:1e6d734c8f95 | 3 | |
mmaretic | 0:1e6d734c8f95 | 4 | Ticker DrsDebouncer; |
mmaretic | 0:1e6d734c8f95 | 5 | Ticker UpozorenjaDebouncer; |
mmaretic | 0:1e6d734c8f95 | 6 | Ticker Multiplexer; |
mmaretic | 0:1e6d734c8f95 | 7 | InterruptIn DrsButton(PB_10); |
mmaretic | 0:1e6d734c8f95 | 8 | InterruptIn UpozorenjaButton(PB_4); |
mmaretic | 0:1e6d734c8f95 | 9 | AnalogIn Ain(PC_0); |
mmaretic | 0:1e6d734c8f95 | 10 | PwmOut servo(PA_10); |
mmaretic | 0:1e6d734c8f95 | 11 | |
mmaretic | 0:1e6d734c8f95 | 12 | char zaPrikazati[10]; |
mmaretic | 0:1e6d734c8f95 | 13 | |
mmaretic | 0:1e6d734c8f95 | 14 | SedamSeg prikaz; |
mmaretic | 0:1e6d734c8f95 | 15 | |
mmaretic | 0:1e6d734c8f95 | 16 | volatile enum state{ |
mmaretic | 0:1e6d734c8f95 | 17 | BRZINA, |
mmaretic | 0:1e6d734c8f95 | 18 | DRS, |
mmaretic | 0:1e6d734c8f95 | 19 | UPOZORENJA |
mmaretic | 0:1e6d734c8f95 | 20 | } s; |
mmaretic | 0:1e6d734c8f95 | 21 | |
mmaretic | 0:1e6d734c8f95 | 22 | void drsInt(); |
mmaretic | 0:1e6d734c8f95 | 23 | void debouncedDrsInt(); |
mmaretic | 0:1e6d734c8f95 | 24 | void upozorenjaInt(); |
mmaretic | 0:1e6d734c8f95 | 25 | void debouncedUpozorenjaInt(); |
mmaretic | 0:1e6d734c8f95 | 26 | void displaySeg(); |
mmaretic | 0:1e6d734c8f95 | 27 | |
mmaretic | 0:1e6d734c8f95 | 28 | int main() { |
mmaretic | 0:1e6d734c8f95 | 29 | |
mmaretic | 0:1e6d734c8f95 | 30 | float ADCvalue; |
mmaretic | 0:1e6d734c8f95 | 31 | |
mmaretic | 0:1e6d734c8f95 | 32 | servo.period_ms(20); |
mmaretic | 0:1e6d734c8f95 | 33 | servo.pulsewidth_us(1250); |
mmaretic | 0:1e6d734c8f95 | 34 | |
mmaretic | 0:1e6d734c8f95 | 35 | DrsButton.mode(PullDown); |
mmaretic | 0:1e6d734c8f95 | 36 | DrsButton.rise(&drsInt); |
mmaretic | 0:1e6d734c8f95 | 37 | DrsButton.fall(&drsInt); |
mmaretic | 0:1e6d734c8f95 | 38 | |
mmaretic | 0:1e6d734c8f95 | 39 | UpozorenjaButton.mode(PullDown); |
mmaretic | 0:1e6d734c8f95 | 40 | UpozorenjaButton.rise(&upozorenjaInt); |
mmaretic | 0:1e6d734c8f95 | 41 | UpozorenjaButton.fall(&upozorenjaInt); |
mmaretic | 0:1e6d734c8f95 | 42 | |
mmaretic | 0:1e6d734c8f95 | 43 | Multiplexer.attach(&displaySeg,0.005); |
mmaretic | 0:1e6d734c8f95 | 44 | |
mmaretic | 0:1e6d734c8f95 | 45 | while(1){ |
mmaretic | 0:1e6d734c8f95 | 46 | switch(s){ |
mmaretic | 0:1e6d734c8f95 | 47 | case DRS: |
mmaretic | 0:1e6d734c8f95 | 48 | servo.pulsewidth_us(2000); |
mmaretic | 0:1e6d734c8f95 | 49 | sprintf(zaPrikazati,"%s","DRS"); |
mmaretic | 0:1e6d734c8f95 | 50 | break; |
mmaretic | 0:1e6d734c8f95 | 51 | case UPOZORENJA: |
mmaretic | 0:1e6d734c8f95 | 52 | servo.pulsewidth_us(1250); |
mmaretic | 0:1e6d734c8f95 | 53 | sprintf(zaPrikazati,"%s","UPO"); |
mmaretic | 0:1e6d734c8f95 | 54 | break; |
mmaretic | 0:1e6d734c8f95 | 55 | default: |
mmaretic | 0:1e6d734c8f95 | 56 | servo.pulsewidth_us(1250); |
mmaretic | 0:1e6d734c8f95 | 57 | ADCvalue = Ain - 0.03; |
mmaretic | 0:1e6d734c8f95 | 58 | ADCvalue = (ADCvalue < 0) ? 0 : ADCvalue; |
mmaretic | 0:1e6d734c8f95 | 59 | ADCvalue *= 309.27; |
mmaretic | 0:1e6d734c8f95 | 60 | sprintf(zaPrikazati,"%i",(int)ADCvalue); |
mmaretic | 0:1e6d734c8f95 | 61 | if(ADCvalue < 10){ |
mmaretic | 0:1e6d734c8f95 | 62 | zaPrikazati[2] = zaPrikazati[0]; |
mmaretic | 0:1e6d734c8f95 | 63 | zaPrikazati[0] = '0'; |
mmaretic | 0:1e6d734c8f95 | 64 | zaPrikazati[1] = '0'; |
mmaretic | 0:1e6d734c8f95 | 65 | } |
mmaretic | 0:1e6d734c8f95 | 66 | else if(ADCvalue < 100){ |
mmaretic | 0:1e6d734c8f95 | 67 | zaPrikazati[2] = zaPrikazati[1]; |
mmaretic | 0:1e6d734c8f95 | 68 | zaPrikazati[1] = zaPrikazati[0]; |
mmaretic | 0:1e6d734c8f95 | 69 | zaPrikazati[0] = '0'; |
mmaretic | 0:1e6d734c8f95 | 70 | } |
mmaretic | 0:1e6d734c8f95 | 71 | break; |
mmaretic | 0:1e6d734c8f95 | 72 | } |
mmaretic | 0:1e6d734c8f95 | 73 | |
mmaretic | 0:1e6d734c8f95 | 74 | wait(0.1); |
mmaretic | 0:1e6d734c8f95 | 75 | } |
mmaretic | 0:1e6d734c8f95 | 76 | } |
mmaretic | 0:1e6d734c8f95 | 77 | |
mmaretic | 0:1e6d734c8f95 | 78 | void drsInt(){ |
mmaretic | 0:1e6d734c8f95 | 79 | DrsButton.disable_irq(); |
mmaretic | 0:1e6d734c8f95 | 80 | DrsDebouncer.attach(&debouncedDrsInt,0.02); |
mmaretic | 0:1e6d734c8f95 | 81 | } |
mmaretic | 0:1e6d734c8f95 | 82 | |
mmaretic | 0:1e6d734c8f95 | 83 | void debouncedDrsInt(){ |
mmaretic | 0:1e6d734c8f95 | 84 | DrsDebouncer.detach(); |
mmaretic | 0:1e6d734c8f95 | 85 | s = (DrsButton && !UpozorenjaButton) ? DRS : (UpozorenjaButton ? UPOZORENJA : BRZINA); |
mmaretic | 0:1e6d734c8f95 | 86 | DrsButton.enable_irq(); |
mmaretic | 0:1e6d734c8f95 | 87 | } |
mmaretic | 0:1e6d734c8f95 | 88 | |
mmaretic | 0:1e6d734c8f95 | 89 | void upozorenjaInt(){ |
mmaretic | 0:1e6d734c8f95 | 90 | UpozorenjaButton.disable_irq(); |
mmaretic | 0:1e6d734c8f95 | 91 | UpozorenjaDebouncer.attach(&debouncedUpozorenjaInt,0.02); |
mmaretic | 0:1e6d734c8f95 | 92 | } |
mmaretic | 0:1e6d734c8f95 | 93 | |
mmaretic | 0:1e6d734c8f95 | 94 | void debouncedUpozorenjaInt(){ |
mmaretic | 0:1e6d734c8f95 | 95 | UpozorenjaDebouncer.detach(); |
mmaretic | 0:1e6d734c8f95 | 96 | s = UpozorenjaButton ? UPOZORENJA : (DrsButton ? DRS : BRZINA); |
mmaretic | 0:1e6d734c8f95 | 97 | UpozorenjaButton.enable_irq(); |
mmaretic | 0:1e6d734c8f95 | 98 | } |
mmaretic | 0:1e6d734c8f95 | 99 | |
mmaretic | 0:1e6d734c8f95 | 100 | void displaySeg(){ |
mmaretic | 0:1e6d734c8f95 | 101 | prikaz.displaySeg(zaPrikazati); |
mmaretic | 0:1e6d734c8f95 | 102 | } |