Sonar Proximity Audio Alert for Robot

Dependencies:   HC_SR04_Ultrasonic_Library Motor mbed-rtos mbed

Fork of rtos_basic by mbed official

Committer:
juubs
Date:
Mon Mar 13 18:35:56 2017 +0000
Revision:
12:42d63181dbdb
Lab 4 Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
juubs 12:42d63181dbdb 1 #include "mbed.h"
juubs 12:42d63181dbdb 2 // a new class to play a note on Speaker based on PwmOut class
juubs 12:42d63181dbdb 3 class Speaker
juubs 12:42d63181dbdb 4 {
juubs 12:42d63181dbdb 5 public:
juubs 12:42d63181dbdb 6 Speaker(PinName pin) : _pin(pin) {
juubs 12:42d63181dbdb 7 // _pin(pin) means pass pin to the Speaker Constructor
juubs 12:42d63181dbdb 8 }
juubs 12:42d63181dbdb 9 // class method to play a note based on PwmOut class
juubs 12:42d63181dbdb 10 void PlayNote(float frequency, float duration, float volume) {
juubs 12:42d63181dbdb 11 _pin.period(1.0/frequency);
juubs 12:42d63181dbdb 12 _pin = volume/2.0;
juubs 12:42d63181dbdb 13 wait(duration);
juubs 12:42d63181dbdb 14 _pin = 0.0;
juubs 12:42d63181dbdb 15 }
juubs 12:42d63181dbdb 16
juubs 12:42d63181dbdb 17 private:
juubs 12:42d63181dbdb 18 PwmOut _pin;
juubs 12:42d63181dbdb 19 };