A simple asteroids-like game utilizing various Mbed-compatible sensors

Dependencies:   mbed 4DGL-uLCD-SE PinDetect

Committer:
sralph3
Date:
Thu Jan 03 19:56:27 2019 +0000
Revision:
8:137330cfe63d
Parent:
0:f2cc64948895
Jan 3, 2019

Who changed what in which revision?

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