sat

Dependencies:   Displej mbed

https://os.mbed.com/media/uploads/IsusKrist/mikroupravljaci.jpg

Committer:
IsusKrist
Date:
Wed May 04 15:48:51 2022 +0000
Revision:
0:5c66146653b6
Sat

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IsusKrist 0:5c66146653b6 1 #include "mbed.h"
IsusKrist 0:5c66146653b6 2 #include "Displej.h"
IsusKrist 0:5c66146653b6 3
IsusKrist 0:5c66146653b6 4
IsusKrist 0:5c66146653b6 5 DigitalIn switch_namestanje_min(D3);
IsusKrist 0:5c66146653b6 6 DigitalIn switch_namestanje_sat(D2);
IsusKrist 0:5c66146653b6 7 InterruptIn button(PB_1);
IsusKrist 0:5c66146653b6 8
IsusKrist 0:5c66146653b6 9 Timer debounce;
IsusKrist 0:5c66146653b6 10 Ticker ticker_min;
IsusKrist 0:5c66146653b6 11
IsusKrist 0:5c66146653b6 12 int namestit_min=0;
IsusKrist 0:5c66146653b6 13 int namestit_sat=0;
IsusKrist 0:5c66146653b6 14 int sati=23;
IsusKrist 0:5c66146653b6 15 int minute=59;
IsusKrist 0:5c66146653b6 16
IsusKrist 0:5c66146653b6 17 class Sat{
IsusKrist 0:5c66146653b6 18 public:
IsusKrist 0:5c66146653b6 19 Sat(int pocetniSat,int pocetnaMinute){
IsusKrist 0:5c66146653b6 20 _sati=pocetniSat;
IsusKrist 0:5c66146653b6 21 _minute=pocetnaMinute;
IsusKrist 0:5c66146653b6 22 }
IsusKrist 0:5c66146653b6 23 void prikaz(){
IsusKrist 0:5c66146653b6 24 //Q1
IsusKrist 0:5c66146653b6 25 QSegment=0x01;
IsusKrist 0:5c66146653b6 26 LSegment=SegConvert(_sati,1);// jedan ide kad je polje obratno dok uzimas digite
IsusKrist 0:5c66146653b6 27 wait(0.003);
IsusKrist 0:5c66146653b6 28 //Q2
IsusKrist 0:5c66146653b6 29 QSegment=0x02;
IsusKrist 0:5c66146653b6 30 LSegment=SegConvert(_sati,0);
IsusKrist 0:5c66146653b6 31 wait(0.003);
IsusKrist 0:5c66146653b6 32 //Q2 dvotocka
IsusKrist 0:5c66146653b6 33 QSegment=0x02;
IsusKrist 0:5c66146653b6 34 LSegment=SegConvert(-1,0);
IsusKrist 0:5c66146653b6 35 wait(0.003);
IsusKrist 0:5c66146653b6 36 //Q3
IsusKrist 0:5c66146653b6 37 QSegment=0x04;
IsusKrist 0:5c66146653b6 38 LSegment=SegConvert(_minute,1);
IsusKrist 0:5c66146653b6 39 wait(0.003);
IsusKrist 0:5c66146653b6 40 //Q4
IsusKrist 0:5c66146653b6 41 QSegment=0x08;
IsusKrist 0:5c66146653b6 42 LSegment=SegConvert(_minute,0);
IsusKrist 0:5c66146653b6 43 wait(0.005);
IsusKrist 0:5c66146653b6 44 }
IsusKrist 0:5c66146653b6 45 void setSati(int h){
IsusKrist 0:5c66146653b6 46 _sati=h;
IsusKrist 0:5c66146653b6 47 }
IsusKrist 0:5c66146653b6 48 void setMinute(int m){
IsusKrist 0:5c66146653b6 49 _minute = m;
IsusKrist 0:5c66146653b6 50 }
IsusKrist 0:5c66146653b6 51 private:
IsusKrist 0:5c66146653b6 52 int _sati,_minute;
IsusKrist 0:5c66146653b6 53 };
IsusKrist 0:5c66146653b6 54
IsusKrist 0:5c66146653b6 55 void otkucaj(void);
IsusKrist 0:5c66146653b6 56 void toggle(void);
IsusKrist 0:5c66146653b6 57
IsusKrist 0:5c66146653b6 58 int main(){
IsusKrist 0:5c66146653b6 59 ticker_min.attach(&otkucaj,60.0);
IsusKrist 0:5c66146653b6 60 debounce.start();
IsusKrist 0:5c66146653b6 61 switch_namestanje_min.mode(PullUp);
IsusKrist 0:5c66146653b6 62 switch_namestanje_sat.mode(PullUp);
IsusKrist 0:5c66146653b6 63 button.rise(&toggle);
IsusKrist 0:5c66146653b6 64 Sat sat(sati,minute);
IsusKrist 0:5c66146653b6 65 while(1) {
IsusKrist 0:5c66146653b6 66 namestit_min=switch_namestanje_min==0?0:1;
IsusKrist 0:5c66146653b6 67 namestit_sat=switch_namestanje_sat==0?0:1;
IsusKrist 0:5c66146653b6 68 sat.setSati(sati);
IsusKrist 0:5c66146653b6 69 sat.setMinute(minute);
IsusKrist 0:5c66146653b6 70 sat.prikaz();
IsusKrist 0:5c66146653b6 71 }
IsusKrist 0:5c66146653b6 72 }
IsusKrist 0:5c66146653b6 73 void otkucaj(){
IsusKrist 0:5c66146653b6 74 if(namestit_sat==1 && namestit_min==1){
IsusKrist 0:5c66146653b6 75 if(minute==59){
IsusKrist 0:5c66146653b6 76 minute=0;
IsusKrist 0:5c66146653b6 77 if(sati==23){
IsusKrist 0:5c66146653b6 78 sati=0;
IsusKrist 0:5c66146653b6 79 }else{
IsusKrist 0:5c66146653b6 80 sati++;
IsusKrist 0:5c66146653b6 81 }
IsusKrist 0:5c66146653b6 82 }else{
IsusKrist 0:5c66146653b6 83 minute++;
IsusKrist 0:5c66146653b6 84 }
IsusKrist 0:5c66146653b6 85 }
IsusKrist 0:5c66146653b6 86 }
IsusKrist 0:5c66146653b6 87
IsusKrist 0:5c66146653b6 88 void toggle() {
IsusKrist 0:5c66146653b6 89 if (debounce.read_ms()>100 && (namestit_min==0||namestit_sat==0)){
IsusKrist 0:5c66146653b6 90 if(namestit_min==0 && namestit_sat==1){
IsusKrist 0:5c66146653b6 91 if(minute<59){
IsusKrist 0:5c66146653b6 92 minute++;
IsusKrist 0:5c66146653b6 93 }else{
IsusKrist 0:5c66146653b6 94 if(sati<23){
IsusKrist 0:5c66146653b6 95 sati++;
IsusKrist 0:5c66146653b6 96 }else{
IsusKrist 0:5c66146653b6 97 sati=0;
IsusKrist 0:5c66146653b6 98 }
IsusKrist 0:5c66146653b6 99 minute=0;
IsusKrist 0:5c66146653b6 100 }
IsusKrist 0:5c66146653b6 101 }else if(namestit_min==1 && namestit_sat==0){
IsusKrist 0:5c66146653b6 102 if(sati<23){
IsusKrist 0:5c66146653b6 103 sati++;
IsusKrist 0:5c66146653b6 104 }else{
IsusKrist 0:5c66146653b6 105 sati=0;
IsusKrist 0:5c66146653b6 106 }
IsusKrist 0:5c66146653b6 107 }
IsusKrist 0:5c66146653b6 108 }
IsusKrist 0:5c66146653b6 109 debounce.reset();
IsusKrist 0:5c66146653b6 110 }