PWM program which uses PwmOut class determining at what point does the change of LED state become unrecognizable (19E042PIM).
main.cpp@1:aa5a8936af37, 2021-10-28 (annotated)
- Committer:
- tzwell
- Date:
- Thu Oct 28 11:03:44 2021 +0000
- Revision:
- 1:aa5a8936af37
- Parent:
- 0:84d44d377c03
Updated comments and code structure
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tzwell | 0:84d44d377c03 | 1 | /* |
tzwell | 0:84d44d377c03 | 2 | * Primer PWM-a za STM32L476RG napisan |
tzwell | 0:84d44d377c03 | 3 | * koristeci mbed.h biblioteku koji koji demonstrira |
tzwell | 0:84d44d377c03 | 4 | * mogucnosti PwmOut objekta preko write atributa. |
tzwell | 0:84d44d377c03 | 5 | * |
tzwell | 0:84d44d377c03 | 6 | * Katedra za Elektroniku i digitalne sisteme |
tzwell | 0:84d44d377c03 | 7 | * Elektrotehnicki fakultet |
tzwell | 0:84d44d377c03 | 8 | * Beograd |
tzwell | 0:84d44d377c03 | 9 | * |
tzwell | 0:84d44d377c03 | 10 | * Oktobar 2021. |
tzwell | 0:84d44d377c03 | 11 | * |
tzwell | 0:84d44d377c03 | 12 | */ |
tzwell | 0:84d44d377c03 | 13 | |
tzwell | 0:84d44d377c03 | 14 | /* |
tzwell | 0:84d44d377c03 | 15 | * Biblioteke za uvoz: |
tzwell | 0:84d44d377c03 | 16 | */ |
tzwell | 0:84d44d377c03 | 17 | #include "mbed.h" |
tzwell | 0:84d44d377c03 | 18 | |
tzwell | 0:84d44d377c03 | 19 | /* |
tzwell | 0:84d44d377c03 | 20 | * Definisanje makroa: |
tzwell | 0:84d44d377c03 | 21 | */ |
tzwell | 0:84d44d377c03 | 22 | #define PWM_PERIOD 20 |
tzwell | 0:84d44d377c03 | 23 | #define PWM_PULSE_WIDTH 0.5 |
tzwell | 0:84d44d377c03 | 24 | |
tzwell | 0:84d44d377c03 | 25 | /* |
tzwell | 0:84d44d377c03 | 26 | * Globalne promenljive: |
tzwell | 0:84d44d377c03 | 27 | */ |
tzwell | 0:84d44d377c03 | 28 | PwmOut DiodicaNaPloci(LED1); // Kreiranje promenljive diode |
tzwell | 0:84d44d377c03 | 29 | |
tzwell | 0:84d44d377c03 | 30 | /* |
tzwell | 0:84d44d377c03 | 31 | * Deklaracija funkcija: |
tzwell | 0:84d44d377c03 | 32 | */ |
tzwell | 0:84d44d377c03 | 33 | |
tzwell | 0:84d44d377c03 | 34 | /* |
tzwell | 0:84d44d377c03 | 35 | * Glavna funkcija: |
tzwell | 0:84d44d377c03 | 36 | */ |
tzwell | 0:84d44d377c03 | 37 | int main() |
tzwell | 0:84d44d377c03 | 38 | { |
tzwell | 1:aa5a8936af37 | 39 | // Inicijalizacija i funckije koje se jednom izvrsavaju: |
tzwell | 1:aa5a8936af37 | 40 | |
tzwell | 0:84d44d377c03 | 41 | // Prvo se zada period treperenja diode, a potom trajanje impulsa: |
tzwell | 0:84d44d377c03 | 42 | DiodicaNaPloci.period_ms(PWM_PERIOD); // Period treperenja traje 4 sekunde |
tzwell | 0:84d44d377c03 | 43 | DiodicaNaPloci.write(PWM_PULSE_WIDTH); // Dioda ukljucena tokom 2 |
tzwell | 1:aa5a8936af37 | 44 | while (true); // Izvrsavanje programa |
tzwell | 0:84d44d377c03 | 45 | } |
tzwell | 0:84d44d377c03 | 46 | |
tzwell | 0:84d44d377c03 | 47 | /* |
tzwell | 0:84d44d377c03 | 48 | * Definicija funkcija: |
tzwell | 0:84d44d377c03 | 49 | */ |