victor gomez
/
5-Buzzer
Buzzer
main.cpp@0:ed488385c247, 2021-07-21 (annotated)
- Committer:
- thevic16
- Date:
- Wed Jul 21 19:17:50 2021 +0000
- Revision:
- 0:ed488385c247
Buzzer;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thevic16 | 0:ed488385c247 | 1 | #include "mbed.h" |
thevic16 | 0:ed488385c247 | 2 | #include "platform/mbed_thread.h" |
thevic16 | 0:ed488385c247 | 3 | |
thevic16 | 0:ed488385c247 | 4 | PwmOut buzzer(D3); |
thevic16 | 0:ed488385c247 | 5 | |
thevic16 | 0:ed488385c247 | 6 | int main() { |
thevic16 | 0:ed488385c247 | 7 | |
thevic16 | 0:ed488385c247 | 8 | float Nota_C4 = 262; |
thevic16 | 0:ed488385c247 | 9 | float Nota_A4 = 440; |
thevic16 | 0:ed488385c247 | 10 | float Nota_E4 = 659; |
thevic16 | 0:ed488385c247 | 11 | |
thevic16 | 0:ed488385c247 | 12 | while(1){ |
thevic16 | 0:ed488385c247 | 13 | |
thevic16 | 0:ed488385c247 | 14 | buzzer.period(1.0/Nota_C4); // Configurando el periodo, que es equivalente a frecuencia (veces que se reproducira el tono por segundo) |
thevic16 | 0:ed488385c247 | 15 | buzzer.write(0.5); |
thevic16 | 0:ed488385c247 | 16 | thread_sleep_for(200); |
thevic16 | 0:ed488385c247 | 17 | |
thevic16 | 0:ed488385c247 | 18 | buzzer.period(1.0/Nota_A4); // Configurando el periodo, que es equivalente a frecuencia (veces que se reproducira el tono por segundo) |
thevic16 | 0:ed488385c247 | 19 | buzzer.write(0.5); |
thevic16 | 0:ed488385c247 | 20 | thread_sleep_for(200); |
thevic16 | 0:ed488385c247 | 21 | |
thevic16 | 0:ed488385c247 | 22 | buzzer.period(1.0/Nota_E4); // Configurando el periodo, que es equivalente a frecuencia (veces que se reproducira el tono por segundo) |
thevic16 | 0:ed488385c247 | 23 | buzzer.write(0.5); |
thevic16 | 0:ed488385c247 | 24 | thread_sleep_for(200); |
thevic16 | 0:ed488385c247 | 25 | |
thevic16 | 0:ed488385c247 | 26 | } |
thevic16 | 0:ed488385c247 | 27 | } |