PURS ZI 009

Committer:
tbjazic
Date:
Wed Sep 07 15:46:01 2016 +0000
Revision:
0:1843b5f93694
initial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tbjazic 0:1843b5f93694 1 #include "mbed.h"
tbjazic 0:1843b5f93694 2 #include "Beepaj.h"
tbjazic 0:1843b5f93694 3
tbjazic 0:1843b5f93694 4 Beepaj::Beepaj(PinName pinTipkala, PinName pinZvucnika) : pokreni(pinTipkala), zvucnik(pinZvucnika) {
tbjazic 0:1843b5f93694 5 pokreni.rise(this, &Beepaj::generirajSignal);
tbjazic 0:1843b5f93694 6 debounce.start();
tbjazic 0:1843b5f93694 7 zvucnik = 0;
tbjazic 0:1843b5f93694 8 zvucnik.period(1.0f/1e3);
tbjazic 0:1843b5f93694 9 }
tbjazic 0:1843b5f93694 10
tbjazic 0:1843b5f93694 11 void Beepaj::generirajSignal() {
tbjazic 0:1843b5f93694 12 if (debounce.read_ms() > 20) {
tbjazic 0:1843b5f93694 13 ukljuciBeep();
tbjazic 0:1843b5f93694 14 ticker.attach(this, &Beepaj::ukljuciBeep, 1);
tbjazic 0:1843b5f93694 15 vrijemeSignala.attach(this, &Beepaj::iskljuciSignal, 4.5);
tbjazic 0:1843b5f93694 16 debounce.reset();
tbjazic 0:1843b5f93694 17 }
tbjazic 0:1843b5f93694 18 }
tbjazic 0:1843b5f93694 19
tbjazic 0:1843b5f93694 20 void Beepaj::ukljuciBeep() {
tbjazic 0:1843b5f93694 21 zvucnik = 0.5;
tbjazic 0:1843b5f93694 22 vrijemeBeepa.attach(this, &Beepaj::iskljuciBeep, 0.5);
tbjazic 0:1843b5f93694 23 }
tbjazic 0:1843b5f93694 24
tbjazic 0:1843b5f93694 25 void Beepaj::iskljuciBeep() {
tbjazic 0:1843b5f93694 26 zvucnik = 0;
tbjazic 0:1843b5f93694 27 }
tbjazic 0:1843b5f93694 28
tbjazic 0:1843b5f93694 29 void Beepaj::iskljuciSignal() {
tbjazic 0:1843b5f93694 30 zvucnik = 0;
tbjazic 0:1843b5f93694 31 ticker.detach();
tbjazic 0:1843b5f93694 32 }