Ispis na tri 7-segmentna display-a

Dependencies:   mbed trostrukiSedamSeg

https://os.mbed.com/media/uploads/mmaretic/prototip_volana_formule_1.pdf

Committer:
mmaretic
Date:
Thu Dec 02 20:38:04 2021 +0000
Revision:
3:f941bac1f8a9
Parent:
2:3227eef26c80
e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mmaretic 0:1e6d734c8f95 1 #include "mbed.h"
mmaretic 0:1e6d734c8f95 2 #include "trostrukiSedamSeg.h"
mmaretic 0:1e6d734c8f95 3
mmaretic 2:3227eef26c80 4 Ticker DrsDebouncer; // Timeri za debouncanje interrupta
mmaretic 0:1e6d734c8f95 5 Ticker UpozorenjaDebouncer;
mmaretic 2:3227eef26c80 6 Ticker Multiplexer; // Timer za multipleksiranje displaya
mmaretic 2:3227eef26c80 7 InterruptIn DrsButton(PB_10); // Intterupt tipkala
mmaretic 0:1e6d734c8f95 8 InterruptIn UpozorenjaButton(PB_4);
mmaretic 2:3227eef26c80 9 AnalogIn Ain(PC_0); // Analogni ulaz za brzinu
mmaretic 2:3227eef26c80 10 PwmOut servo(PA_10); // Pwm izlaz za ukljucivanje serva
mmaretic 0:1e6d734c8f95 11
mmaretic 2:3227eef26c80 12 char zaPrikazati[4];
mmaretic 0:1e6d734c8f95 13
mmaretic 2:3227eef26c80 14 SedamSeg prikaz; // Inicijalizacija klase SedamSeg
mmaretic 0:1e6d734c8f95 15
mmaretic 2:3227eef26c80 16 // Enum za koristenje u switch case-u
mmaretic 0:1e6d734c8f95 17 volatile enum state{
mmaretic 0:1e6d734c8f95 18 BRZINA,
mmaretic 0:1e6d734c8f95 19 DRS,
mmaretic 0:1e6d734c8f95 20 UPOZORENJA
mmaretic 0:1e6d734c8f95 21 } s;
mmaretic 0:1e6d734c8f95 22
mmaretic 2:3227eef26c80 23 // Pototipi funkcija
mmaretic 0:1e6d734c8f95 24 void drsInt();
mmaretic 0:1e6d734c8f95 25 void debouncedDrsInt();
mmaretic 0:1e6d734c8f95 26 void upozorenjaInt();
mmaretic 0:1e6d734c8f95 27 void debouncedUpozorenjaInt();
mmaretic 0:1e6d734c8f95 28 void displaySeg();
mmaretic 0:1e6d734c8f95 29
mmaretic 0:1e6d734c8f95 30 int main() {
mmaretic 0:1e6d734c8f95 31
mmaretic 0:1e6d734c8f95 32 float ADCvalue;
mmaretic 0:1e6d734c8f95 33
mmaretic 0:1e6d734c8f95 34 servo.period_ms(20);
mmaretic 0:1e6d734c8f95 35 servo.pulsewidth_us(1250);
mmaretic 0:1e6d734c8f95 36
mmaretic 0:1e6d734c8f95 37 DrsButton.mode(PullDown);
mmaretic 0:1e6d734c8f95 38 DrsButton.rise(&drsInt);
mmaretic 0:1e6d734c8f95 39 DrsButton.fall(&drsInt);
mmaretic 0:1e6d734c8f95 40
mmaretic 0:1e6d734c8f95 41 UpozorenjaButton.mode(PullDown);
mmaretic 0:1e6d734c8f95 42 UpozorenjaButton.rise(&upozorenjaInt);
mmaretic 0:1e6d734c8f95 43 UpozorenjaButton.fall(&upozorenjaInt);
mmaretic 0:1e6d734c8f95 44
mmaretic 0:1e6d734c8f95 45 Multiplexer.attach(&displaySeg,0.005);
mmaretic 0:1e6d734c8f95 46
mmaretic 0:1e6d734c8f95 47 while(1){
mmaretic 0:1e6d734c8f95 48 switch(s){
mmaretic 0:1e6d734c8f95 49 case DRS:
mmaretic 0:1e6d734c8f95 50 servo.pulsewidth_us(2000);
mmaretic 0:1e6d734c8f95 51 sprintf(zaPrikazati,"%s","DRS");
mmaretic 0:1e6d734c8f95 52 break;
mmaretic 0:1e6d734c8f95 53 case UPOZORENJA:
mmaretic 0:1e6d734c8f95 54 servo.pulsewidth_us(1250);
mmaretic 0:1e6d734c8f95 55 sprintf(zaPrikazati,"%s","UPO");
mmaretic 0:1e6d734c8f95 56 break;
mmaretic 0:1e6d734c8f95 57 default:
mmaretic 0:1e6d734c8f95 58 servo.pulsewidth_us(1250);
mmaretic 2:3227eef26c80 59 // Skaliranje ulaza s 0 - 1 na 0 - 300kmh
mmaretic 0:1e6d734c8f95 60 ADCvalue = Ain - 0.03;
mmaretic 0:1e6d734c8f95 61 ADCvalue = (ADCvalue < 0) ? 0 : ADCvalue;
mmaretic 0:1e6d734c8f95 62 ADCvalue *= 309.27;
mmaretic 2:3227eef26c80 63
mmaretic 0:1e6d734c8f95 64 sprintf(zaPrikazati,"%i",(int)ADCvalue);
mmaretic 0:1e6d734c8f95 65 if(ADCvalue < 10){
mmaretic 0:1e6d734c8f95 66 zaPrikazati[2] = zaPrikazati[0];
mmaretic 0:1e6d734c8f95 67 zaPrikazati[0] = '0';
mmaretic 0:1e6d734c8f95 68 zaPrikazati[1] = '0';
mmaretic 0:1e6d734c8f95 69 }
mmaretic 0:1e6d734c8f95 70 else if(ADCvalue < 100){
mmaretic 0:1e6d734c8f95 71 zaPrikazati[2] = zaPrikazati[1];
mmaretic 0:1e6d734c8f95 72 zaPrikazati[1] = zaPrikazati[0];
mmaretic 0:1e6d734c8f95 73 zaPrikazati[0] = '0';
mmaretic 0:1e6d734c8f95 74 }
mmaretic 0:1e6d734c8f95 75 break;
mmaretic 0:1e6d734c8f95 76 }
mmaretic 0:1e6d734c8f95 77
mmaretic 0:1e6d734c8f95 78 wait(0.1);
mmaretic 0:1e6d734c8f95 79 }
mmaretic 0:1e6d734c8f95 80 }
mmaretic 0:1e6d734c8f95 81
mmaretic 0:1e6d734c8f95 82 void drsInt(){
mmaretic 0:1e6d734c8f95 83 DrsButton.disable_irq();
mmaretic 0:1e6d734c8f95 84 DrsDebouncer.attach(&debouncedDrsInt,0.02);
mmaretic 0:1e6d734c8f95 85 }
mmaretic 0:1e6d734c8f95 86
mmaretic 0:1e6d734c8f95 87 void debouncedDrsInt(){
mmaretic 0:1e6d734c8f95 88 DrsDebouncer.detach();
mmaretic 0:1e6d734c8f95 89 s = (DrsButton && !UpozorenjaButton) ? DRS : (UpozorenjaButton ? UPOZORENJA : BRZINA);
mmaretic 0:1e6d734c8f95 90 DrsButton.enable_irq();
mmaretic 0:1e6d734c8f95 91 }
mmaretic 0:1e6d734c8f95 92
mmaretic 0:1e6d734c8f95 93 void upozorenjaInt(){
mmaretic 0:1e6d734c8f95 94 UpozorenjaButton.disable_irq();
mmaretic 0:1e6d734c8f95 95 UpozorenjaDebouncer.attach(&debouncedUpozorenjaInt,0.02);
mmaretic 0:1e6d734c8f95 96 }
mmaretic 0:1e6d734c8f95 97
mmaretic 0:1e6d734c8f95 98 void debouncedUpozorenjaInt(){
mmaretic 0:1e6d734c8f95 99 UpozorenjaDebouncer.detach();
mmaretic 0:1e6d734c8f95 100 s = UpozorenjaButton ? UPOZORENJA : (DrsButton ? DRS : BRZINA);
mmaretic 0:1e6d734c8f95 101 UpozorenjaButton.enable_irq();
mmaretic 0:1e6d734c8f95 102 }
mmaretic 0:1e6d734c8f95 103
mmaretic 0:1e6d734c8f95 104 void displaySeg(){
mmaretic 0:1e6d734c8f95 105 prikaz.displaySeg(zaPrikazati);
mmaretic 0:1e6d734c8f95 106 }