World In Balance game

Dependencies:   4DGL-uLCD-SE PinDetect mbed

Committer:
jchin32
Date:
Wed Nov 08 20:25:03 2017 +0000
Revision:
0:1305fa20a8db
World In Balance Game

Who changed what in which revision?

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