this is a game very similar to pong, use touch sensor to hit the ball on the LCD back and forth

Dependencies:   SLCD TSI mbed

Files at this revision

API Documentation at this revision

Comitter:
MattShilling
Date:
Wed Sep 28 07:00:13 2016 +0000
Commit message:
this is a game, very similar to pong;

Changed in this revision

SLCD.lib Show annotated file Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SLCD.lib	Wed Sep 28 07:00:13 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Wed Sep 28 07:00:13 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/mbed/code/TSI/#1a60ef257879
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 28 07:00:13 2016 +0000
@@ -0,0 +1,113 @@
+#include "mbed.h"
+#include "TSISensor.h"
+#include "SLCD.h"
+
+Serial pc(USBTX, USBRX);
+SLCD lcd;
+TSISensor tsi; // touch sensor
+
+bool send = true;
+bool hit_right = false;
+float speed = 0.2;
+
+void send_ball_left(){
+    lcd.clear();
+    lcd.CharPosition=2; 
+    lcd.putc('o');
+    wait(speed);
+    
+    lcd.clear();
+    lcd.CharPosition=1; 
+    lcd.putc('o');
+    wait(speed);
+    
+    lcd.clear();
+
+}
+
+void send_ball_right(){
+    lcd.clear();
+    lcd.CharPosition=0; 
+    lcd.putc('o');
+    wait(speed);
+    
+    lcd.clear();
+    lcd.CharPosition=1; 
+    lcd.putc('o');
+    wait(speed);
+    
+    lcd.clear();
+    lcd.CharPosition=2; 
+    lcd.putc('o');
+    wait(speed);
+}
+
+void send_ball_back(){
+    
+    lcd.clear();
+    lcd.CharPosition=1; 
+    lcd.putc('o');
+    wait(speed);
+    
+    lcd.clear();
+    lcd.CharPosition=2; 
+    lcd.putc('o');
+    wait(speed);
+}
+
+void check_swipe_left(){
+    lcd.clear();
+    lcd.CharPosition=3; 
+    lcd.putc('o');
+    wait(speed);
+    
+    if (tsi.readPercentage() > .75){
+        send_ball_left();
+        send = false;
+        hit_right = true;
+    }
+    else {
+        lcd.clear();
+        lcd.CharPosition=1; 
+        lcd.printf("no");
+        wait(.7);
+        send = true;
+        hit_right = false;
+        speed = speed + 0.01;
+    }
+}
+        
+void check_swipe_right(){
+    lcd.clear();
+    lcd.CharPosition=0; 
+    lcd.putc('o');
+    wait(speed);
+    if (tsi.readPercentage() > .1 && tsi.readPercentage() < .5){
+        send_ball_back();
+        send = false;
+        speed = speed - 0.01;
+    }
+    else {
+        lcd.clear(); 
+        lcd.printf("no");
+        wait(.7);
+        send = true;
+        speed = speed + 0.01;
+    }
+}   
+    
+    
+
+
+int main(void) {
+     
+     
+     // initiate LCD
+     lcd.Home();  
+     
+     while (true) {
+        if (send) {send_ball_right();}
+        check_swipe_left();
+        if(hit_right){check_swipe_right();}
+     }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 28 07:00:13 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85
\ No newline at end of file