![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Punjenje i pražnjenje spremnika vode
Dependencies: mbed
spremnikVode.h@1:07c01a8966ae, 23 months ago (annotated)
- Committer:
- mrimac
- Date:
- Fri Sep 09 00:14:08 2022 +0000
- Revision:
- 1:07c01a8966ae
- Parent:
- 0:1a5027292b9a
Spremnik vode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mrimac | 0:1a5027292b9a | 1 | #include "mbed.h" |
mrimac | 0:1a5027292b9a | 2 | |
mrimac | 0:1a5027292b9a | 3 | DigitalIn sensor(D9); |
mrimac | 1:07c01a8966ae | 4 | InterruptIn sw(D8); |
mrimac | 1:07c01a8966ae | 5 | DigitalIn button(D2); |
mrimac | 1:07c01a8966ae | 6 | DigitalOut yLed(A5); |
mrimac | 0:1a5027292b9a | 7 | DigitalOut led(A0); |
mrimac | 0:1a5027292b9a | 8 | DigitalOut gLed(A1); |
mrimac | 1:07c01a8966ae | 9 | DigitalOut buzzer(A2); |
mrimac | 1:07c01a8966ae | 10 | bool gLedLight; |
mrimac | 0:1a5027292b9a | 11 | Ticker ticker; |
mrimac | 0:1a5027292b9a | 12 | bool full; |
mrimac | 1:07c01a8966ae | 13 | bool on; |
mrimac | 0:1a5027292b9a | 14 | |
mrimac | 0:1a5027292b9a | 15 | void flash(DigitalOut lamp, int period) { |
mrimac | 0:1a5027292b9a | 16 | lamp = !lamp; |
mrimac | 0:1a5027292b9a | 17 | wait_ms(period); |
mrimac | 0:1a5027292b9a | 18 | printf ("Water level is low! "); |
mrimac | 0:1a5027292b9a | 19 | } |
mrimac | 0:1a5027292b9a | 20 | |
mrimac | 0:1a5027292b9a | 21 | bool startFilling () { |
mrimac | 0:1a5027292b9a | 22 | printf("Water is filling. "); |
mrimac | 1:07c01a8966ae | 23 | yLed = true; |
mrimac | 0:1a5027292b9a | 24 | wait_ms(5000); |
mrimac | 0:1a5027292b9a | 25 | printf("Water level is now ok. "); |
mrimac | 0:1a5027292b9a | 26 | return true; |
mrimac | 0:1a5027292b9a | 27 | } |
mrimac | 0:1a5027292b9a | 28 | |
mrimac | 1:07c01a8966ae | 29 | void flashGreen() { |
mrimac | 1:07c01a8966ae | 30 | gLedLight = !gLedLight; |
mrimac | 1:07c01a8966ae | 31 | } |
mrimac | 1:07c01a8966ae | 32 | |
mrimac | 1:07c01a8966ae | 33 | void buzz(){ |
mrimac | 1:07c01a8966ae | 34 | buzzer = true; |
mrimac | 1:07c01a8966ae | 35 | wait_ms(2000); |
mrimac | 1:07c01a8966ae | 36 | buzzer = false; |
mrimac | 1:07c01a8966ae | 37 | } |
mrimac | 1:07c01a8966ae | 38 | |
mrimac | 1:07c01a8966ae | 39 | void buttonPressed () { |
mrimac | 1:07c01a8966ae | 40 | if (full) { |
mrimac | 1:07c01a8966ae | 41 | ticker.attach(&buzz, 2.0); |
mrimac | 1:07c01a8966ae | 42 | } |
mrimac | 0:1a5027292b9a | 43 | } |
mrimac | 0:1a5027292b9a | 44 | |
mrimac | 1:07c01a8966ae | 45 | void turnOn () { |
mrimac | 1:07c01a8966ae | 46 | on = !on; |
mrimac | 1:07c01a8966ae | 47 | |
mrimac | 1:07c01a8966ae | 48 | } |