TVZ, Spec Elo, Mikroupravljaci, Popunjenost garaze

Dependencies:   mbed SwitchLED TextLCD BluetoothSerial

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "SwitchLED.h"
00004 TextLCD lcd(D4, D5, D9, D10, D11, D12); //rs,e,d4,d5,d6,d7
00005 // TextLCD lcd(D4, D5, D9, D10, D11, D12,TextLCD::LCD8x2);
00006 DigitalIn SIG1(A0);
00007 DigitalIn SIG2(A1);
00008 Switch redled(D6);
00009 DigitalOut LEDslobodno(D7);
00010 InterruptIn button(USER_BUTTON);
00011 Ticker Slobodno;
00012 int n=7, i=7, j=0;    // maksimalan kapacitet garaže, trenutan broj auti, sljedeći broj auti
00013 int Counter(DigitalIn SIG1, DigitalIn SIG2,int n, int j);
00014 void flip(){
00015     LEDslobodno = !LEDslobodno;
00016 }
00017 void alarm(void);
00018 int main()
00019 {
00020     LEDslobodno=0;
00021     while(1) {
00022         button.rise(&alarm);
00023         if(SIG1 || SIG2) {
00024             j=Counter(SIG1, SIG2, n, j);
00025             if(j==n && i==(n-1)) { //nema slobodnih mjesta i pali R_LED
00026                 redled.SW();
00027             }
00028             if(j==n ) { //nema slobodnih mjesta i pali R_LED
00029                 Slobodno.detach();
00030                 LEDslobodno=0;
00031                 lcd.printf("Nema slobodnih mjesta");
00032             }
00033             if(i==n && j==(n-1)) { //Gasi R_LED kad ima slobodnih mjesta
00034                 redled.SW();
00035             }
00036             i=j;
00037             if(i<n) {
00038                 Slobodno.attach(&flip,1);
00039                 lcd.printf("Slobodno: %d",n-i); //ima slobodnih mjesta, ispis na ekran i blinkanje G_LED
00040             }
00041         }
00042         wait(2);
00043         lcd.cls();
00044     }
00045 }
00046 int Counter(DigitalIn SIG1, DigitalIn SIG2, int n, int j)
00047 {
00048 
00049     if(SIG1 && j>0 && SIG2==0) {
00050         j--;
00051     }
00052     if(SIG2==1 && j<n && j!=n && SIG1==0) {
00053         j++;
00054     }
00055     return j;
00056 }
00057 void alarm()
00058 {
00059     while(1) {
00060         LEDslobodno=0;
00061         lcd.cls();
00062         lcd.printf("Pozar u garazi"); //Požar u garaži
00063         wait(20);
00064         break;
00065     }
00066 
00067 }