Simulacija rada semafora s 4 LED diode, 7 segmentog display-a, zvučnika, tipkala i potenciometra

Dependencies:   mbed

https://os.mbed.com/media/uploads/dcindric/picture1.png

Committer:
dcindric
Date:
Fri May 07 10:33:28 2021 +0000
Revision:
1:1b7ec94fe4ab
Parent:
0:2531c2b824f9
Konstukcijski Cindric

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dcindric 0:2531c2b824f9 1 #include "svjetla.h"
dcindric 0:2531c2b824f9 2 #include "segmentni.h"
dcindric 0:2531c2b824f9 3 #include "buzzer.h"
dcindric 0:2531c2b824f9 4
dcindric 0:2531c2b824f9 5 DigitalOut red(PC_0);
dcindric 0:2531c2b824f9 6 DigitalOut yellow(PC_1);
dcindric 0:2531c2b824f9 7 DigitalOut green(PC_2);
dcindric 0:2531c2b824f9 8 DigitalOut pjesaciLed(LED2);
dcindric 0:2531c2b824f9 9
dcindric 0:2531c2b824f9 10 Timer debounce;
dcindric 0:2531c2b824f9 11 Timer timerPjesaci;
dcindric 0:2531c2b824f9 12 Serial pc(USBTX, USBRX);
dcindric 0:2531c2b824f9 13 Buzz buzzer(PC_9);
dcindric 0:2531c2b824f9 14
dcindric 0:2531c2b824f9 15 void semafor()
dcindric 0:2531c2b824f9 16 {
dcindric 0:2531c2b824f9 17 stop();
dcindric 0:2531c2b824f9 18 wait(3);
dcindric 0:2531c2b824f9 19 dopunsko();
dcindric 0:2531c2b824f9 20 wait(3);
dcindric 0:2531c2b824f9 21 SegConvert(11);
dcindric 0:2531c2b824f9 22 pripremi();
dcindric 0:2531c2b824f9 23 wait(1);
dcindric 0:2531c2b824f9 24 kreni();
dcindric 0:2531c2b824f9 25 wait(3);
dcindric 0:2531c2b824f9 26 uspori();
dcindric 0:2531c2b824f9 27 wait(1);
dcindric 0:2531c2b824f9 28 }
dcindric 0:2531c2b824f9 29
dcindric 0:2531c2b824f9 30 void stop()
dcindric 0:2531c2b824f9 31 {
dcindric 0:2531c2b824f9 32 red = 1;
dcindric 0:2531c2b824f9 33 yellow = 0;
dcindric 0:2531c2b824f9 34 green = 0;
dcindric 0:2531c2b824f9 35 pc.printf("Crveno \n \r");
dcindric 0:2531c2b824f9 36 }
dcindric 0:2531c2b824f9 37
dcindric 0:2531c2b824f9 38 void pripremi()
dcindric 0:2531c2b824f9 39 {
dcindric 0:2531c2b824f9 40 red = 1;
dcindric 0:2531c2b824f9 41 yellow = 1;
dcindric 0:2531c2b824f9 42 green = 0;
dcindric 0:2531c2b824f9 43 pc.printf("Zuto \n \r");
dcindric 0:2531c2b824f9 44 }
dcindric 0:2531c2b824f9 45
dcindric 0:2531c2b824f9 46 void kreni()
dcindric 0:2531c2b824f9 47 {
dcindric 0:2531c2b824f9 48 red = 0;
dcindric 0:2531c2b824f9 49 yellow = 0;
dcindric 0:2531c2b824f9 50 green = 1;
dcindric 0:2531c2b824f9 51 pc.printf("Zeleno \n \r");
dcindric 0:2531c2b824f9 52 }
dcindric 0:2531c2b824f9 53
dcindric 0:2531c2b824f9 54 void uspori()
dcindric 0:2531c2b824f9 55 {
dcindric 0:2531c2b824f9 56 pc.printf("Zuto \n \r");
dcindric 0:2531c2b824f9 57 red = 0;
dcindric 0:2531c2b824f9 58 yellow = 1;
dcindric 0:2531c2b824f9 59 green = 0;
dcindric 0:2531c2b824f9 60 }
dcindric 0:2531c2b824f9 61
dcindric 0:2531c2b824f9 62 void dopunsko()
dcindric 0:2531c2b824f9 63 {
dcindric 0:2531c2b824f9 64 pc.printf("Dopunsko \n \r");
dcindric 0:2531c2b824f9 65 SegConvert(10);
dcindric 0:2531c2b824f9 66 }
dcindric 0:2531c2b824f9 67
dcindric 0:2531c2b824f9 68 void funkcijaPjesaci()
dcindric 0:2531c2b824f9 69 {
dcindric 0:2531c2b824f9 70 debounce.start();
dcindric 0:2531c2b824f9 71 if (debounce.read_ms()>200) {
dcindric 0:2531c2b824f9 72 stop();
dcindric 0:2531c2b824f9 73 pjesaci();
dcindric 0:2531c2b824f9 74 debounce.reset();
dcindric 0:2531c2b824f9 75 }
dcindric 0:2531c2b824f9 76 }
dcindric 0:2531c2b824f9 77
dcindric 0:2531c2b824f9 78 void pjesaci()
dcindric 0:2531c2b824f9 79 {
dcindric 0:2531c2b824f9 80 pc.printf("Pjesaci \n \r");
dcindric 0:2531c2b824f9 81 timerPjesaci.start();
dcindric 0:2531c2b824f9 82 int vrijeme = 0;
dcindric 0:2531c2b824f9 83 while (timerPjesaci.read()<=10) {
dcindric 0:2531c2b824f9 84 vrijeme = 10 - timerPjesaci.read();
dcindric 0:2531c2b824f9 85 treperenje();
dcindric 0:2531c2b824f9 86 SegConvert(vrijeme);
dcindric 0:2531c2b824f9 87 buzzer.buzz();
dcindric 0:2531c2b824f9 88 wait(0.5);
dcindric 0:2531c2b824f9 89 }
dcindric 0:2531c2b824f9 90 buzzer.buzzOff();
dcindric 0:2531c2b824f9 91 SegConvert(11);
dcindric 0:2531c2b824f9 92 timerPjesaci.stop();
dcindric 0:2531c2b824f9 93 timerPjesaci.reset();
dcindric 0:2531c2b824f9 94 }
dcindric 0:2531c2b824f9 95
dcindric 0:2531c2b824f9 96 void treperenje()
dcindric 0:2531c2b824f9 97 {
dcindric 0:2531c2b824f9 98 pjesaciLed =! pjesaciLed;
dcindric 0:2531c2b824f9 99 }
dcindric 0:2531c2b824f9 100
dcindric 0:2531c2b824f9 101 void kvar()
dcindric 0:2531c2b824f9 102 {
dcindric 0:2531c2b824f9 103 red = 0;
dcindric 0:2531c2b824f9 104 yellow =! yellow;
dcindric 0:2531c2b824f9 105 green = 0;
dcindric 0:2531c2b824f9 106 }