![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
TVZ, Spec Elo, Mikroupravljaci, Popunjenost garaze
Dependencies: mbed SwitchLED TextLCD BluetoothSerial
Program prati koliko je auti trenutno u garaži pomoću IR senzora HW-201 (postavljeno na max. 7 auti) i ispisuje stanje na LDC display-u. U koliko ima slobodnih mjesta zelena LED blinka i ispisuje se broj slobodnih mjesta. Kad broj slobodnih mjesta dođe na 0, ispisuje se "Nema slobodnih mjesta i pali se crvena LED. Prilikom pritiska na user tipkalo B1 prekida se kod i ispisuje se "Pozar u garazi".
main.cpp@1:31557fa549a3, 2022-02-22 (annotated)
- Committer:
- iivankovic
- Date:
- Tue Feb 22 13:13:31 2022 +0000
- Revision:
- 1:31557fa549a3
- Parent:
- 0:6f4570a58585
TVZ, Spec Elo, Mikroupravljaci, Popunjenost garaze
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iivankovic | 0:6f4570a58585 | 1 | #include "mbed.h" |
iivankovic | 0:6f4570a58585 | 2 | #include "TextLCD.h" |
iivankovic | 0:6f4570a58585 | 3 | #include "SwitchLED.h" |
iivankovic | 0:6f4570a58585 | 4 | TextLCD lcd(D4, D5, D9, D10, D11, D12); //rs,e,d4,d5,d6,d7 |
iivankovic | 0:6f4570a58585 | 5 | // TextLCD lcd(D4, D5, D9, D10, D11, D12,TextLCD::LCD8x2); |
iivankovic | 0:6f4570a58585 | 6 | DigitalIn SIG1(A0); |
iivankovic | 0:6f4570a58585 | 7 | DigitalIn SIG2(A1); |
iivankovic | 0:6f4570a58585 | 8 | Switch redled(D6); |
iivankovic | 0:6f4570a58585 | 9 | DigitalOut LEDslobodno(D7); |
iivankovic | 0:6f4570a58585 | 10 | InterruptIn button(USER_BUTTON); |
iivankovic | 0:6f4570a58585 | 11 | Ticker Slobodno; |
iivankovic | 0:6f4570a58585 | 12 | int n=7, i=7, j=0; // maksimalan kapacitet garaže, trenutan broj auti, sljedeći broj auti |
iivankovic | 0:6f4570a58585 | 13 | int Counter(DigitalIn SIG1, DigitalIn SIG2,int n, int j); |
iivankovic | 0:6f4570a58585 | 14 | void flip(){ |
iivankovic | 0:6f4570a58585 | 15 | LEDslobodno = !LEDslobodno; |
iivankovic | 0:6f4570a58585 | 16 | } |
iivankovic | 0:6f4570a58585 | 17 | void alarm(void); |
iivankovic | 0:6f4570a58585 | 18 | int main() |
iivankovic | 0:6f4570a58585 | 19 | { |
iivankovic | 0:6f4570a58585 | 20 | LEDslobodno=0; |
iivankovic | 0:6f4570a58585 | 21 | while(1) { |
iivankovic | 0:6f4570a58585 | 22 | button.rise(&alarm); |
iivankovic | 0:6f4570a58585 | 23 | if(SIG1 || SIG2) { |
iivankovic | 0:6f4570a58585 | 24 | j=Counter(SIG1, SIG2, n, j); |
iivankovic | 0:6f4570a58585 | 25 | if(j==n && i==(n-1)) { //nema slobodnih mjesta i pali R_LED |
iivankovic | 0:6f4570a58585 | 26 | redled.SW(); |
iivankovic | 0:6f4570a58585 | 27 | } |
iivankovic | 0:6f4570a58585 | 28 | if(j==n ) { //nema slobodnih mjesta i pali R_LED |
iivankovic | 0:6f4570a58585 | 29 | Slobodno.detach(); |
iivankovic | 0:6f4570a58585 | 30 | LEDslobodno=0; |
iivankovic | 0:6f4570a58585 | 31 | lcd.printf("Nema slobodnih mjesta"); |
iivankovic | 0:6f4570a58585 | 32 | } |
iivankovic | 0:6f4570a58585 | 33 | if(i==n && j==(n-1)) { //Gasi R_LED kad ima slobodnih mjesta |
iivankovic | 0:6f4570a58585 | 34 | redled.SW(); |
iivankovic | 0:6f4570a58585 | 35 | } |
iivankovic | 0:6f4570a58585 | 36 | i=j; |
iivankovic | 0:6f4570a58585 | 37 | if(i<n) { |
iivankovic | 0:6f4570a58585 | 38 | Slobodno.attach(&flip,1); |
iivankovic | 0:6f4570a58585 | 39 | lcd.printf("Slobodno: %d",n-i); //ima slobodnih mjesta, ispis na ekran i blinkanje G_LED |
iivankovic | 0:6f4570a58585 | 40 | } |
iivankovic | 0:6f4570a58585 | 41 | } |
iivankovic | 0:6f4570a58585 | 42 | wait(2); |
iivankovic | 0:6f4570a58585 | 43 | lcd.cls(); |
iivankovic | 0:6f4570a58585 | 44 | } |
iivankovic | 0:6f4570a58585 | 45 | } |
iivankovic | 0:6f4570a58585 | 46 | int Counter(DigitalIn SIG1, DigitalIn SIG2, int n, int j) |
iivankovic | 0:6f4570a58585 | 47 | { |
iivankovic | 0:6f4570a58585 | 48 | |
iivankovic | 0:6f4570a58585 | 49 | if(SIG1 && j>0 && SIG2==0) { |
iivankovic | 0:6f4570a58585 | 50 | j--; |
iivankovic | 0:6f4570a58585 | 51 | } |
iivankovic | 0:6f4570a58585 | 52 | if(SIG2==1 && j<n && j!=n && SIG1==0) { |
iivankovic | 0:6f4570a58585 | 53 | j++; |
iivankovic | 0:6f4570a58585 | 54 | } |
iivankovic | 0:6f4570a58585 | 55 | return j; |
iivankovic | 0:6f4570a58585 | 56 | } |
iivankovic | 0:6f4570a58585 | 57 | void alarm() |
iivankovic | 0:6f4570a58585 | 58 | { |
iivankovic | 0:6f4570a58585 | 59 | while(1) { |
iivankovic | 0:6f4570a58585 | 60 | LEDslobodno=0; |
iivankovic | 0:6f4570a58585 | 61 | lcd.cls(); |
iivankovic | 0:6f4570a58585 | 62 | lcd.printf("Pozar u garazi"); //Požar u garaži |
iivankovic | 0:6f4570a58585 | 63 | wait(20); |
iivankovic | 0:6f4570a58585 | 64 | break; |
iivankovic | 0:6f4570a58585 | 65 | } |
iivankovic | 0:6f4570a58585 | 66 | |
iivankovic | 0:6f4570a58585 | 67 | } |