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

Committer:
achixx
Date:
Thu Apr 08 15:21:50 2021 +0000
Revision:
2:6cf9d41a5c08
Parent:
0:697252610ff7
Interior V2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
achixx 0:697252610ff7 1 #include "mbed.h"
achixx 0:697252610ff7 2 #include "CHECK.h"
achixx 0:697252610ff7 3 Serial pc(USBTX, USBRX, 9600);
achixx 2:6cf9d41a5c08 4 InterruptIn button(PB_5); // Interrupt on digital pushbutton input - Tun ON lights
achixx 0:697252610ff7 5 DigitalIn limSw(PB_4); // Limit switch on the door
achixx 0:697252610ff7 6 DigitalOut svjetlo(PA_10); // LED strip ON
achixx 0:697252610ff7 7 Check svjetlo2(PB_3); // LED indication for working program
achixx 0:697252610ff7 8 Timer debounce; // define debounce timer
achixx 0:697252610ff7 9 Ticker flipper; // define ticker for check
achixx 0:697252610ff7 10 void toggle(void); // function
achixx 0:697252610ff7 11 // function to the rising edge
achixx 0:697252610ff7 12 //funkcija tickera
achixx 0:697252610ff7 13 void ticker(){
achixx 0:697252610ff7 14 svjetlo2.checking();
achixx 0:697252610ff7 15 }
achixx 0:697252610ff7 16 void toggle() {
achixx 0:697252610ff7 17 if (debounce.read_ms()>200){ // only allow toggle if debounce timer
achixx 0:697252610ff7 18 svjetlo = 1;
achixx 0:697252610ff7 19 pc.printf("\n Svjetlo upaljeno pomocu tipkala.");
achixx 0:697252610ff7 20 wait (5);
achixx 0:697252610ff7 21 svjetlo = 0;
achixx 0:697252610ff7 22 pc.printf("\n Svjetlo ugaseno! \n");
achixx 0:697252610ff7 23 wait (1);}
achixx 0:697252610ff7 24 debounce.reset(); // restart timer when the toggle is performed
achixx 0:697252610ff7 25 }
achixx 0:697252610ff7 26
achixx 0:697252610ff7 27 int main() {
achixx 0:697252610ff7 28 debounce.start();
achixx 0:697252610ff7 29 button.rise(&toggle); // when button is pressed call function toggle
achixx 0:697252610ff7 30 flipper.attach(&ticker, 1.0); // call function to check every 1s
achixx 0:697252610ff7 31 while (1){
achixx 0:697252610ff7 32 wait (0.1);
achixx 0:697252610ff7 33 if (limSw == 1){
achixx 0:697252610ff7 34 svjetlo = 0;}
achixx 0:697252610ff7 35 else if (limSw == 0) {
achixx 0:697252610ff7 36 svjetlo = 1;
achixx 0:697252610ff7 37 wait (5);
achixx 0:697252610ff7 38 svjetlo = 0;
achixx 0:697252610ff7 39 pc.printf("\n Svjetlo upaljeno pomocu senzora.");}
achixx 0:697252610ff7 40 }
achixx 0:697252610ff7 41 }
achixx 0:697252610ff7 42
achixx 0:697252610ff7 43
achixx 0:697252610ff7 44