Ideja projekta: Kada korisnik otvori ulazna vrata kuće/stana/zgrade da se pali svjetlo u stubištu ili ulaznom prostoru. Sve dok su ulazna vrata otvorena, svjetlo će biti upaljeno (limit switch se nalazi negdje u štoku vrata). Ukoliko vrijeme istekne, a korisnik želi još svjetlosti, moguće je pritisnuti gumb (tipkalo) te će se svjetlo upaliti na određen period. U ovom projektu je to period od 3 min (180s).

Dependencies:   mbed

https://os.mbed.com/media/uploads/achixx/wiring.pdf

main.cpp

Committer:
achixx
Date:
2021-04-08
Revision:
2:6cf9d41a5c08
Parent:
0:697252610ff7

File content as of revision 2:6cf9d41a5c08:

#include "mbed.h"
#include "CHECK.h"
Serial pc(USBTX, USBRX, 9600);
InterruptIn button(PB_5); // Interrupt on digital pushbutton input - Tun ON lights
DigitalIn limSw(PB_4); // Limit switch on the door
DigitalOut svjetlo(PA_10); // LED strip ON
Check svjetlo2(PB_3); // LED indication for working program
Timer debounce; // define debounce timer
Ticker flipper;  // define ticker for check
void toggle(void);  // function
 // function to the rising edge
 //funkcija tickera
void ticker(){
    svjetlo2.checking();
}
void toggle() {
if (debounce.read_ms()>200){ // only allow toggle if debounce timer
                 svjetlo = 1;
                 pc.printf("\n Svjetlo upaljeno pomocu tipkala.");
                 wait (5);
                 svjetlo = 0;
                 pc.printf("\n Svjetlo ugaseno! \n");
                 wait (1);}
debounce.reset(); // restart timer when the toggle is performed
}

int main() {
debounce.start();
button.rise(&toggle); // when button is pressed call function toggle
flipper.attach(&ticker, 1.0); // call function to check every 1s
while (1){
    wait (0.1);
    if (limSw == 1){
        svjetlo = 0;}
    else if (limSw == 0) {
        svjetlo = 1;
        wait (5);
        svjetlo = 0;
        pc.printf("\n Svjetlo upaljeno pomocu senzora.");}
}
}