Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Kuhalo.cpp
- Committer:
- tbjazic
- Date:
- 2016-06-27
- Revision:
- 0:5d42120ee981
- Child:
- 1:b2d57993ce40
File content as of revision 0:5d42120ee981:
#include "mbed.h" #include "Kuhalo.h" Kuhalo::Kuhalo(PinName pinTipke1, PinName pinTipke2, PinName pinTipke3, PinName pinTipke4, PinName pinTipkeSnage) : tipka1(pinTipke1), tipka2(pinTipke2), tipka3(pinTipke3), tipka4(pinTipke4), snaga(pinTipkeSnage), ploca1(LED1), ploca2(LED2), ploca3(LED3), ploca4(LED4) { tipka1.rise(this, &Kuhalo::odabirPloce1); tipka2.rise(this, &Kuhalo::odabirPloce2); tipka3.rise(this, &Kuhalo::odabirPloce3); tipka4.rise(this, &Kuhalo::odabirPloce4); snaga.rise(this, &Kuhalo::izborSnage); debounce.start(); odabranaPloca = 0; } void Kuhalo::odabirPloce1() { if (debounce.read_ms() > 20) { odabranaPloca = 1; debounce.reset(); vrijemeZaIzborSnage.attach(this, &Kuhalo::ponistiOdabirPloce, 5); } } void Kuhalo::odabirPloce2() { if (debounce.read_ms() > 20) { odabranaPloca = 2; debounce.reset(); vrijemeZaIzborSnage.attach(this, &Kuhalo::ponistiOdabirPloce, 5); } } void Kuhalo::odabirPloce3() { if (debounce.read_ms() > 20) { odabranaPloca = 3; debounce.reset(); vrijemeZaIzborSnage.attach(this, &Kuhalo::ponistiOdabirPloce, 5); } } void Kuhalo::odabirPloce4() { if (debounce.read_ms() > 20) { odabranaPloca = 4; debounce.reset(); vrijemeZaIzborSnage.attach(this, &Kuhalo::ponistiOdabirPloce, 5); } } void Kuhalo::izborSnage() { if (debounce.read_ms() > 20) { vrijemeZaIzborSnage.detach(); debounce.reset(); odabranaSnaga = ++odabranaSnaga % 5; float snaga = (float) odabranaSnaga / 4; switch(odabranaPloca) { case 1: ploca1 = snaga; break; case 2: ploca2 = snaga; break; case 3: ploca3 = snaga; break; case 4: ploca4 = snaga; break; } } } void Kuhalo::ponistiOdabirPloce() { odabranaPloca = 0; }