Utilities classes for the Zumo Robot
Dependents: ZumoRobotBluetoothControlled Fsl_Zumo
This library represents some useful code for controlling your Zumo Robot.
Diff: Buzzer.cpp
- Revision:
- 7:d2af97b7cc94
- Parent:
- 6:7740c9d8d834
diff -r 7740c9d8d834 -r d2af97b7cc94 Buzzer.cpp --- a/Buzzer.cpp Sun Dec 21 12:46:41 2014 +0000 +++ b/Buzzer.cpp Sun Jul 23 12:51:35 2017 +0000 @@ -2,44 +2,34 @@ // Buzzer.cpp // © 2014 Catalin Craciun -#ifndef BuzzerCpp -#define BuzzerCpp +#include "Buzzer.h" +#define MELODY_LENGTH 5 -#include "Buzzer.h" - -Buzzer::Buzzer(PinName buzzerPinName):buzzerPin(buzzerPinName) -{ - +Buzzer::Buzzer(PinName buzzerPinName):buzzerPin(buzzerPinName) { // Initialising buzzerPin.period_us(0); buzzerPin.pulsewidth_us(0); } -Buzzer::~Buzzer() -{ - +Buzzer::~Buzzer() { // Deinitialising } -void Buzzer::stopBeep() -{ +void Buzzer::stopBeep() { buzzerPin.period_us(0); buzzerPin.pulsewidth_us(0); } -void Buzzer::startBeep(float frequency, float duration) -{ - - buzzerPin.period(1/frequency); +void Buzzer::startBeep(float frequency, float duration) { + buzzerPin.period(1.0f/frequency); buzzerPin.pulsewidth_us(100); timeout.attach(this, &Buzzer::stopBeep, duration); } -void Buzzer::playDefaultMelody() -{ +void Buzzer::playDefaultMelody() { // Playing default melody on buzzer - while (true) { + for (int cycle = 0; cycle < MELODY_LENGTH; cycle++) { buzzerPin.period(16); buzzerPin.pulsewidth_us(200); wait(0.5); @@ -65,5 +55,3 @@ wait(0.5); } } - -#endif // BuzzerCpp \ No newline at end of file