PURS_ZI_010

Dependents:   PURS_ZI_010

Committer:
tbjazic
Date:
Thu Feb 02 14:11:44 2017 +0000
Revision:
0:c1c396a29e74
Initial.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tbjazic 0:c1c396a29e74 1 #include "mbed.h"
tbjazic 0:c1c396a29e74 2 #include "Temperatura.h"
tbjazic 0:c1c396a29e74 3 #include "C12832.h"
tbjazic 0:c1c396a29e74 4
tbjazic 0:c1c396a29e74 5 Temperatura::Temperatura(PinName tipkaloPin, PinName senzorPin, PinName zvucnikPin) : tipkalo(tipkaloPin), senzor(senzorPin), zvucnik(zvucnikPin), lcd(p5, p7, p6, p8, p11) {
tbjazic 0:c1c396a29e74 6 debounce.start();
tbjazic 0:c1c396a29e74 7 lcd.cls();
tbjazic 0:c1c396a29e74 8 lcd.locate(0,3);
tbjazic 0:c1c396a29e74 9 lcd.printf("Mjerenje se moze pokrenuti...");
tbjazic 0:c1c396a29e74 10 mjerenjePokrenuto = ukljucenZvucnik = false;
tbjazic 0:c1c396a29e74 11 zvucnik.period(1.0f / 500);
tbjazic 0:c1c396a29e74 12 tipkalo.rise(this, &Temperatura::startStopMjerenja);
tbjazic 0:c1c396a29e74 13 }
tbjazic 0:c1c396a29e74 14
tbjazic 0:c1c396a29e74 15 void Temperatura::startStopMjerenja() {
tbjazic 0:c1c396a29e74 16 if(debounce.read_ms() > 20) {
tbjazic 0:c1c396a29e74 17 if(!mjerenjePokrenuto) {
tbjazic 0:c1c396a29e74 18 mjerenjePokrenuto = true;
tbjazic 0:c1c396a29e74 19 ticker.attach(this, &Temperatura::mjeriIPrikazi, 0.5);
tbjazic 0:c1c396a29e74 20 } else {
tbjazic 0:c1c396a29e74 21 mjerenjePokrenuto = false;
tbjazic 0:c1c396a29e74 22 ticker.detach();
tbjazic 0:c1c396a29e74 23 lcd.cls();
tbjazic 0:c1c396a29e74 24 lcd.locate(0,3);
tbjazic 0:c1c396a29e74 25 lcd.printf("Mjerenje se moze pokrenuti...");
tbjazic 0:c1c396a29e74 26 }
tbjazic 0:c1c396a29e74 27 debounce.reset();
tbjazic 0:c1c396a29e74 28 }
tbjazic 0:c1c396a29e74 29 }
tbjazic 0:c1c396a29e74 30
tbjazic 0:c1c396a29e74 31
tbjazic 0:c1c396a29e74 32 void Temperatura::mjeriIPrikazi() {
tbjazic 0:c1c396a29e74 33 float temperatura = -25 + (75 - (-25)) / ((3-0.5f)/3.3f) * (senzor.read() - (0.5f/3.3f));
tbjazic 0:c1c396a29e74 34 lcd.cls();
tbjazic 0:c1c396a29e74 35 lcd.locate(0,3);
tbjazic 0:c1c396a29e74 36 if (temperatura >= -25 && temperatura <= 75) {
tbjazic 0:c1c396a29e74 37 lcd.printf("Temperatura: %5.1f °C", temperatura);
tbjazic 0:c1c396a29e74 38 } else {
tbjazic 0:c1c396a29e74 39 lcd.printf("Temperatura izvan mjernog opsega!");
tbjazic 0:c1c396a29e74 40 if (!ukljucenZvucnik) {
tbjazic 0:c1c396a29e74 41 zvucnik = 0.5;
tbjazic 0:c1c396a29e74 42 ukljucenZvucnik = true;
tbjazic 0:c1c396a29e74 43 timeout.attach(this, &Temperatura::iskljuciZvucnik, 0.5);
tbjazic 0:c1c396a29e74 44 }
tbjazic 0:c1c396a29e74 45 }
tbjazic 0:c1c396a29e74 46 }
tbjazic 0:c1c396a29e74 47 void Temperatura::iskljuciZvucnik() {
tbjazic 0:c1c396a29e74 48 zvucnik = 0;
tbjazic 0:c1c396a29e74 49 ukljucenZvucnik = false;
tbjazic 0:c1c396a29e74 50 /* tko se jos zeli igrati s trajanjem pauze izmedju zvucnih signala
tbjazic 0:c1c396a29e74 51 * moze dodati jos jedan timeout objekt vezan na bool varijablu
tbjazic 0:c1c396a29e74 52 * ukljucenZvucnik
tbjazic 0:c1c396a29e74 53 */
tbjazic 0:c1c396a29e74 54 }