Kostadin Chakarov / Mbed 2 deprecated el17kec

Dependencies:   mbed

Revision:
1:b82c4c2de9a8
Parent:
0:2f0362fef062
Child:
2:006a2ddfabb6
diff -r 2f0362fef062 -r b82c4c2de9a8 main.cpp
--- a/main.cpp	Mon Mar 11 18:37:43 2019 +0000
+++ b/main.cpp	Tue Mar 19 11:56:20 2019 +0000
@@ -5,10 +5,82 @@
 Username: el17kec
 Student ID Number:201171978 Date:11/03/2019
 */
+// breakout++ logo sprite
+const int breakout[10][75] =   {
+    { 1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0 },
+    { 1,0,1,0,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1 },
+    { 1,1,0,0,0,0,1,0,0,1,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0 },
+    { 1,1,0,1,1,1,1,0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0 },
+    { 1,0,1,0,0,1,1,0,0,0,1,1,1,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0 },
+    { 1,1,0,1,1,0,0,1,0,0,1,0,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,1,1,1 },
+    { 1,1,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0 },
+    { 1,1,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0 },
+    { 1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0 },
+    { 1,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0 },
+};
 
+///////// pre-processor directives ////////
 #include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "PlayerControl.h"    
+
+/////////////// objects ///////////////
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);  // K64F - pwr from 3V3
+Gamepad pad; // Gamepad buttons
+PlayerControl cont; // Object for player
+
+///////////// function prototypes ///////////////
+void init();
+void welcome();
+void render();
 
-int main()
+///////////// functions ////////////////
+int main() 
+{   
+    int fps = 10;
+    init();
+    welcome();  // waiting for the user to start
+    while(1) 
+    {
+        render();
+        wait(1.0f/fps);
+    }
+}
+
+void init() 
+{
+  // need to initialise LCD and Gamepad
+  lcd.init();
+  pad.init();
+  lcd.setContrast(0.55); // setting contrast to 55% seems good
+  lcd.normalMode();      // normal colour mode
+  lcd.setBrightness(0.5); // put LED backlight on 50%
+}   
+
+void welcome() 
 {
+    lcd.printString("Welcome to",12,0);
+    // x origin, y origin, rows, cols, sprite
+    lcd.drawSprite(5,15,10,75,(int *)breakout);   
+    lcd.printString("Press Start",9,4);
+    lcd.refresh();   
+    
+    // flash the LEDs until start button is pressed 
+    while (pad.check_event(Gamepad::START_PRESSED) == false) 
+    {
+        for (int i = 1; i < 7; i++) 
+        {
+        pad.led(i,1);
+        wait(0.1);
+        pad.led(i,0);
+        }
+    }
+}
 
+void render() {
+    lcd.clear(); // initialise the LCD
+    cont.controlPlayer(pad); 
+    cont.drawPlayer(lcd); 
+    lcd.refresh();
 }
\ No newline at end of file