Jeffery Hurley
/
Asteroids
Simple starter skeleton for asteroids video game.
main.cpp@0:0c450cb95a1e, 2019-02-21 (annotated)
- Committer:
- jhurley31
- Date:
- Thu Feb 21 17:44:23 2019 +0000
- Revision:
- 0:0c450cb95a1e
- Child:
- 1:a6872783beca
Starting the buzzman project
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhurley31 | 0:0c450cb95a1e | 1 | #include "mbed.h" |
jhurley31 | 0:0c450cb95a1e | 2 | #include "Speaker.h" |
jhurley31 | 0:0c450cb95a1e | 3 | #include "PinDetect.h" |
jhurley31 | 0:0c450cb95a1e | 4 | |
jhurley31 | 0:0c450cb95a1e | 5 | // Setup push button pins |
jhurley31 | 0:0c450cb95a1e | 6 | PinDetect pb_left(p16); |
jhurley31 | 0:0c450cb95a1e | 7 | PinDetect pb_right(p17); |
jhurley31 | 0:0c450cb95a1e | 8 | PinDetect pb_up(p18); |
jhurley31 | 0:0c450cb95a1e | 9 | PinDetect pb_down(p18); |
jhurley31 | 0:0c450cb95a1e | 10 | // setup instance of new Speaker class, mySpeaker using pin 21 |
jhurley31 | 0:0c450cb95a1e | 11 | // the pin must be a PWM output pin |
jhurley31 | 0:0c450cb95a1e | 12 | Speaker mySpeaker(p21); |
jhurley31 | 0:0c450cb95a1e | 13 | //--------------------------------------------------------------------------------------------------- |
jhurley31 | 0:0c450cb95a1e | 14 | // Callback routine is interrupt activated by a debounced pb_left hit |
jhurley31 | 0:0c450cb95a1e | 15 | // That is … this code runs with interrupt is generated by first button press |
jhurley31 | 0:0c450cb95a1e | 16 | void pb_left_hit_callback (void) |
jhurley31 | 0:0c450cb95a1e | 17 | { |
jhurley31 | 0:0c450cb95a1e | 18 | // Tell Buzzman to go left |
jhurley31 | 0:0c450cb95a1e | 19 | //************* |
jhurley31 | 0:0c450cb95a1e | 20 | // Fill in needed Code here |
jhurley31 | 0:0c450cb95a1e | 21 | //************* |
jhurley31 | 0:0c450cb95a1e | 22 | |
jhurley31 | 0:0c450cb95a1e | 23 | } |
jhurley31 | 0:0c450cb95a1e | 24 | //--------------------------------------------------------------------------------------------------- |
jhurley31 | 0:0c450cb95a1e | 25 | // Callback routine is interrupt activated by a debounced pb_right hit |
jhurley31 | 0:0c450cb95a1e | 26 | // That is … this code runs with interrupt is generated by first button press |
jhurley31 | 0:0c450cb95a1e | 27 | void pb_right_hit_callback (void) |
jhurley31 | 0:0c450cb95a1e | 28 | { |
jhurley31 | 0:0c450cb95a1e | 29 | // Tell Buzzman to go right |
jhurley31 | 0:0c450cb95a1e | 30 | //************* |
jhurley31 | 0:0c450cb95a1e | 31 | // Fill in needed Code here |
jhurley31 | 0:0c450cb95a1e | 32 | //************* |
jhurley31 | 0:0c450cb95a1e | 33 | |
jhurley31 | 0:0c450cb95a1e | 34 | } |
jhurley31 | 0:0c450cb95a1e | 35 | //--------------------------------------------------------------------------------------------------- |
jhurley31 | 0:0c450cb95a1e | 36 | int main() |
jhurley31 | 0:0c450cb95a1e | 37 | { |
jhurley31 | 0:0c450cb95a1e | 38 | //setup push buttons |
jhurley31 | 0:0c450cb95a1e | 39 | pb1.mode(PullUp); |
jhurley31 | 0:0c450cb95a1e | 40 | pb2.mode(PullUp); |
jhurley31 | 0:0c450cb95a1e | 41 | pb3.mode(PullUp); |
jhurley31 | 0:0c450cb95a1e | 42 | // Delay for initial pullup to take effect |
jhurley31 | 0:0c450cb95a1e | 43 | wait(.01); |
jhurley31 | 0:0c450cb95a1e | 44 | // Setup Interrupt callback functions for a pb hit |
jhurley31 | 0:0c450cb95a1e | 45 | pb1.attach_deasserted(&pb1_hit_callback); |
jhurley31 | 0:0c450cb95a1e | 46 | pb2.attach_deasserted(&pb2_hit_callback); |
jhurley31 | 0:0c450cb95a1e | 47 | pb3.attach_deasserted(&pb3_hit_callback); |
jhurley31 | 0:0c450cb95a1e | 48 | // Start sampling pb inputs using interrupts |
jhurley31 | 0:0c450cb95a1e | 49 | pb1.setSampleFrequency(); |
jhurley31 | 0:0c450cb95a1e | 50 | pb2.setSampleFrequency(); |
jhurley31 | 0:0c450cb95a1e | 51 | pb3.setSampleFrequency(); |
jhurley31 | 0:0c450cb95a1e | 52 | // pushbuttons now setup and running |
jhurley31 | 0:0c450cb95a1e | 53 | while(1) |
jhurley31 | 0:0c450cb95a1e | 54 | { |
jhurley31 | 0:0c450cb95a1e | 55 | myled4 = !myled4; |
jhurley31 | 0:0c450cb95a1e | 56 | wait(0.5); |
jhurley31 | 0:0c450cb95a1e | 57 | } |
jhurley31 | 0:0c450cb95a1e | 58 | } //end main |