![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Postepeno paljenje LED dioda pomću potenciometra.
Dependencies: BluetoothSerial SeeedShieldBot buzzer mbed
main.cpp@0:7ff53fefbbf2, 23 months ago (annotated)
- Committer:
- ndurdevic
- Date:
- Thu Sep 08 21:59:42 2022 +0000
- Revision:
- 0:7ff53fefbbf2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ndurdevic | 0:7ff53fefbbf2 | 1 | #include "buzzer.h" |
ndurdevic | 0:7ff53fefbbf2 | 2 | #include "mbed.h" |
ndurdevic | 0:7ff53fefbbf2 | 3 | |
ndurdevic | 0:7ff53fefbbf2 | 4 | #ifndef MBED_BEEP_H |
ndurdevic | 0:7ff53fefbbf2 | 5 | #define MBED_BEEP_H |
ndurdevic | 0:7ff53fefbbf2 | 6 | |
ndurdevic | 0:7ff53fefbbf2 | 7 | #include "mbed.h" |
ndurdevic | 0:7ff53fefbbf2 | 8 | |
ndurdevic | 0:7ff53fefbbf2 | 9 | namespace mbed { |
ndurdevic | 0:7ff53fefbbf2 | 10 | class Beep { |
ndurdevic | 0:7ff53fefbbf2 | 11 | |
ndurdevic | 0:7ff53fefbbf2 | 12 | public: |
ndurdevic | 0:7ff53fefbbf2 | 13 | |
ndurdevic | 0:7ff53fefbbf2 | 14 | Beep (D5); |
ndurdevic | 0:7ff53fefbbf2 | 15 | |
ndurdevic | 0:7ff53fefbbf2 | 16 | void beep (float frekvencija, float trajanje); |
ndurdevic | 0:7ff53fefbbf2 | 17 | |
ndurdevic | 0:7ff53fefbbf2 | 18 | void nobeep(); |
ndurdevic | 0:7ff53fefbbf2 | 19 | |
ndurdevic | 0:7ff53fefbbf2 | 20 | private : |
ndurdevic | 0:7ff53fefbbf2 | 21 | PwmOut _pwm; |
ndurdevic | 0:7ff53fefbbf2 | 22 | Timeout toff; |
ndurdevic | 0:7ff53fefbbf2 | 23 | }; |
ndurdevic | 0:7ff53fefbbf2 | 24 | |
ndurdevic | 0:7ff53fefbbf2 | 25 | } |
ndurdevic | 0:7ff53fefbbf2 | 26 | #endif |
ndurdevic | 0:7ff53fefbbf2 | 27 | |
ndurdevic | 0:7ff53fefbbf2 | 28 | |
ndurdevic | 0:7ff53fefbbf2 | 29 | Beep buzzer(D5); |
ndurdevic | 0:7ff53fefbbf2 | 30 | DigitalOut red(D4); |
ndurdevic | 0:7ff53fefbbf2 | 31 | DigitalOut yellow(D2); |
ndurdevic | 0:7ff53fefbbf2 | 32 | DigitalOut green(D3); |
ndurdevic | 0:7ff53fefbbf2 | 33 | DigitalOut LED(LED2); |
ndurdevic | 0:7ff53fefbbf2 | 34 | |
ndurdevic | 0:7ff53fefbbf2 | 35 | |
ndurdevic | 0:7ff53fefbbf2 | 36 | Serial pc(USBTX, USBRX); //potenciometar |
ndurdevic | 0:7ff53fefbbf2 | 37 | |
ndurdevic | 0:7ff53fefbbf2 | 38 | AnalogIn potenciometar(A0); |
ndurdevic | 0:7ff53fefbbf2 | 39 | float ADCdata; |
ndurdevic | 0:7ff53fefbbf2 | 40 | float vrijednost; |
ndurdevic | 0:7ff53fefbbf2 | 41 | |
ndurdevic | 0:7ff53fefbbf2 | 42 | |
ndurdevic | 0:7ff53fefbbf2 | 43 | float frekvencija1 = 900; |
ndurdevic | 0:7ff53fefbbf2 | 44 | float frekvencija2 = 800; |
ndurdevic | 0:7ff53fefbbf2 | 45 | float frekvencija3 = 700; |
ndurdevic | 0:7ff53fefbbf2 | 46 | float frekvencija4 = 600; |
ndurdevic | 0:7ff53fefbbf2 | 47 | float trajanje=0.5; |
ndurdevic | 0:7ff53fefbbf2 | 48 | |
ndurdevic | 0:7ff53fefbbf2 | 49 | void titranje(void); |
ndurdevic | 0:7ff53fefbbf2 | 50 | void toggle(void); |
ndurdevic | 0:7ff53fefbbf2 | 51 | |
ndurdevic | 0:7ff53fefbbf2 | 52 | int main() |
ndurdevic | 0:7ff53fefbbf2 | 53 | { |
ndurdevic | 0:7ff53fefbbf2 | 54 | while (1) { |
ndurdevic | 0:7ff53fefbbf2 | 55 | vrijednost = potenciometar; |
ndurdevic | 0:7ff53fefbbf2 | 56 | |
ndurdevic | 0:7ff53fefbbf2 | 57 | if (vrijednost <=0.2) { |
ndurdevic | 0:7ff53fefbbf2 | 58 | while (1) { |
ndurdevic | 0:7ff53fefbbf2 | 59 | green = 0; |
ndurdevic | 0:7ff53fefbbf2 | 60 | red = 1; |
ndurdevic | 0:7ff53fefbbf2 | 61 | yellow = 0; |
ndurdevic | 0:7ff53fefbbf2 | 62 | break; |
ndurdevic | 0:7ff53fefbbf2 | 63 | } |
ndurdevic | 0:7ff53fefbbf2 | 64 | } |
ndurdevic | 0:7ff53fefbbf2 | 65 | if (vrijednost >0.2 & vrijednost <=0.5) { |
ndurdevic | 0:7ff53fefbbf2 | 66 | green = 0; |
ndurdevic | 0:7ff53fefbbf2 | 67 | red = 0; |
ndurdevic | 0:7ff53fefbbf2 | 68 | yellow = 1; |
ndurdevic | 0:7ff53fefbbf2 | 69 | break; |
ndurdevic | 0:7ff53fefbbf2 | 70 | } |
ndurdevic | 0:7ff53fefbbf2 | 71 | if (vrijednost >0.5 & vrijednost <=0.8) { |
ndurdevic | 0:7ff53fefbbf2 | 72 | green = 1; |
ndurdevic | 0:7ff53fefbbf2 | 73 | red = 0; |
ndurdevic | 0:7ff53fefbbf2 | 74 | yellow = 0; |
ndurdevic | 0:7ff53fefbbf2 | 75 | break; |
ndurdevic | 0:7ff53fefbbf2 | 76 | } |
ndurdevic | 0:7ff53fefbbf2 | 77 | if (vrijednost >0.8 & vrijednost <1) { |
ndurdevic | 0:7ff53fefbbf2 | 78 | green = 1; |
ndurdevic | 0:7ff53fefbbf2 | 79 | red = 1; |
ndurdevic | 0:7ff53fefbbf2 | 80 | yellow = 1; |
ndurdevic | 0:7ff53fefbbf2 | 81 | break; |
ndurdevic | 0:7ff53fefbbf2 | 82 | } |
ndurdevic | 0:7ff53fefbbf2 | 83 | } |
ndurdevic | 0:7ff53fefbbf2 | 84 | } |
ndurdevic | 0:7ff53fefbbf2 | 85 | |
ndurdevic | 0:7ff53fefbbf2 | 86 | void titranje(void) |
ndurdevic | 0:7ff53fefbbf2 | 87 | { |
ndurdevic | 0:7ff53fefbbf2 | 88 | yellow = !yellow; |
ndurdevic | 0:7ff53fefbbf2 | 89 | red = !red; |
ndurdevic | 0:7ff53fefbbf2 | 90 | green=!green; |
ndurdevic | 0:7ff53fefbbf2 | 91 | } |
ndurdevic | 0:7ff53fefbbf2 | 92 |