The IoTBot is a WiFi-enabled rover built from the Shadow Robot kit. It is controlled from a web interface running on the Adafruit Huzzah ESP8266 WiFi module and implements a pair of Hall-effect sensors on the motors to keep the wheels spinning at the same speed. Additionally, it uses a Sharp IR sensor to detect walls in front of the robot and prevent it from crashing.
Dependencies: mbed-dev mbed-rtos
Fork of huzzah_helloWorld by
SongPlayer.h
00001 #include "mbed.h" 00002 // new class to play a note on Speaker based on PwmOut class 00003 class SongPlayer 00004 { 00005 public: 00006 SongPlayer(PinName pin) : _pin(pin) { 00007 // _pin(pin) means pass pin to the constructor 00008 } 00009 // class method to play a note based on PwmOut class 00010 void PlaySong(float frequency[], float duration[], float volume=1.0) { 00011 vol = volume; 00012 notecount = 0; 00013 _pin.period(1.0/frequency[notecount]); 00014 _pin = volume/2.0; 00015 noteduration.attach(this,&SongPlayer::nextnote, duration[notecount]); 00016 // setup timer to interrupt for next note to play 00017 frequencyptr = frequency; 00018 durationptr = duration; 00019 //returns after first note starts to play 00020 } 00021 void nextnote(); 00022 private: 00023 Timeout noteduration; 00024 PwmOut _pin; 00025 int notecount; 00026 float vol; 00027 float * frequencyptr; 00028 float * durationptr; 00029 }; 00030 //Interrupt Routine to play next note 00031 void SongPlayer::nextnote() 00032 { 00033 _pin = 0.0; 00034 notecount++; //setup next note in song 00035 if (durationptr[notecount]!=0.0) { 00036 _pin.period(1.0/frequencyptr[notecount]); 00037 noteduration.attach(this,&SongPlayer::nextnote, durationptr[notecount]); 00038 _pin = vol/2.0; 00039 } else 00040 _pin = 0.0; //turn off on last note 00041 }
Generated on Wed Jul 27 2022 00:14:12 by
1.7.2
