Jeffery Hurley
/
Asteroids
Simple starter skeleton for asteroids video game.
Diff: main.cpp
- Revision:
- 1:a6872783beca
- Parent:
- 0:0c450cb95a1e
- Child:
- 2:30020ddfccf6
--- a/main.cpp Thu Feb 21 17:44:23 2019 +0000 +++ b/main.cpp Sat Feb 23 21:38:45 2019 +0000 @@ -1,21 +1,34 @@ #include "mbed.h" #include "Speaker.h" #include "PinDetect.h" +#include "BuzzyGraphics.h" +#include "uLCD_4DGL.h" -// Setup push button pins +//////////////////////////////////////// +// Setup instance of LCD display +uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin; +//////////////////////////////////////// +// Setup instances of push button pins PinDetect pb_left(p16); PinDetect pb_right(p17); PinDetect pb_up(p18); -PinDetect pb_down(p18); -// setup instance of new Speaker class, mySpeaker using pin 21 -// the pin must be a PWM output pin -Speaker mySpeaker(p21); +PinDetect pb_down(p19); + +Speaker SpeakerOut(p21); +////////////////////////////////////////////////////////////////////// +// Interrupt routine +// used to output next analog sample whenever a timer interrupt occurs +void Sample_timer_interrupt(void) +{ + // send next analog sample out to D to A + SpeakerOut.PlayNextValue(); + +} //--------------------------------------------------------------------------------------------------- // Callback routine is interrupt activated by a debounced pb_left hit -// That is … this code runs with interrupt is generated by first button press void pb_left_hit_callback (void) { - // Tell Buzzman to go left + // Tell Buzzy to go left //************* // Fill in needed Code here //************* @@ -23,10 +36,29 @@ } //--------------------------------------------------------------------------------------------------- // Callback routine is interrupt activated by a debounced pb_right hit -// That is … this code runs with interrupt is generated by first button press void pb_right_hit_callback (void) { - // Tell Buzzman to go right + // Tell Buzzy to go right + //************* + // Fill in needed Code here + //************* + +} +//--------------------------------------------------------------------------------------------------- +// Callback routine is interrupt activated by a debounced pb_up hit +void pb_up_hit_callback (void) +{ + // Tell Buzzy to go up + //************* + // Fill in needed Code here + //************* + +} +//--------------------------------------------------------------------------------------------------- +// Callback routine is interrupt activated by a debounced pb_down hit +void pb_down_hit_callback (void) +{ + // Tell Buzzy to go down //************* // Fill in needed Code here //************* @@ -35,24 +67,36 @@ //--------------------------------------------------------------------------------------------------- int main() { -//setup push buttons -pb1.mode(PullUp); -pb2.mode(PullUp); -pb3.mode(PullUp); -// Delay for initial pullup to take effect -wait(.01); -// Setup Interrupt callback functions for a pb hit -pb1.attach_deasserted(&pb1_hit_callback); -pb2.attach_deasserted(&pb2_hit_callback); -pb3.attach_deasserted(&pb3_hit_callback); -// Start sampling pb inputs using interrupts -pb1.setSampleFrequency(); -pb2.setSampleFrequency(); -pb3.setSampleFrequency(); -// pushbuttons now setup and running -while(1) -{ -myled4 = !myled4; -wait(0.5); -} + //setup push buttons + pb_left.mode(PullUp); + pb_right.mode(PullUp); + pb_up.mode(PullUp); + pb_down.mode(PullUp); + // Delay for initial pullup to take effect + wait(.01); + // Setup Interrupt callback functions for a pb hit + pb_left.attach_deasserted(&pb_left_hit_callback); + pb_right.attach_deasserted(&pb_right_hit_callback); + pb_up.attach_deasserted(&pb_up_hit_callback); + pb_down.attach_deasserted(&pb_down_hit_callback); + // Setup speaker + SpeakerOut.period(1.0/200000.0); + + //Setup LCD display + uLCD.display_control(PORTRAIT); + uLCD.background_color(BLACK); + uLCD.cls(); + uLCD.baudrate(BAUD_3000000); //jack up baud rate to max for fast display + wait(1.0); + // DrawMaze(); + // Start sampling pb inputs using interrupts + pb_left.setSampleFrequency(); + pb_right.setSampleFrequency(); + pb_up.setSampleFrequency(); + pb_down.setSampleFrequency(); + // pushbuttons now setup and running + while(1) + { + + } } //end main \ No newline at end of file