Dependencies:   Motor

(notes)

Revision:
18:6c93ec600402
Parent:
16:40f697a68445
Child:
21:f8f6c1f5743c
--- a/main.cpp	Tue Dec 11 01:28:10 2018 +0000
+++ b/main.cpp	Tue Dec 11 02:06:44 2018 +0000
@@ -7,32 +7,6 @@
 Thread thread1;
 Thread thread2;
 
-// Define devices
-Motor left(p22, p16, p15); // pwm, fwd, rev
-Motor right(p23, p19, p20); // pwm, fwd, rev
-BusOut myled(LED1,LED2,LED3,LED4);
-RGBLed myRGBled(p26, p25, p24); // red, green, blue
-rgbSensor rgbsensor(p28, p27);
-Serial blue(p13, p14); // serial tx, serial rx
-enum speed_state { accelerating, braking, coasting };
-XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);    //Change these to pins used
-
-//Game state variables
-int progress = 0;
-int position = 1;
-int current_item = 0;
-bool holding_item = false;
-bool itembox = false;
-bool is_hit = false;
-float speed_cmd = 0.0;
-float max_speed = 1.0;
-float acceleration_rate = 0.04;
-float brake_rate = 0.1;
-float coast_rate = 0.02;
-int cstate;
-speed_state sstate = coasting;
-bool collide = false;
-
 // Global game actions
 bool paused = false;
 void check_unpause() {
@@ -140,28 +114,32 @@
     while(true){
         if(itembox && current_item == 0) {
             //playsound
-            for(int n = 0, n < 10, n++){    //flash the led to simulate slot machine effect
-                myRGBled(1.0,0.0,0.0);
+            for(int n = 0; n < 10; n++){    //flash the led to simulate slot machine effect
+                myRGBled.write(1.0,0.0,0.0);
                 ThisThread::sleep_for(50);
-                myRGBled(0.0,1.0,0.0);
+                myRGBled.write(0.0,1.0,0.0);
                 ThisThread::sleep_for(50);
-                myRGBled(0.0,0.0,1.0);
+                myRGBled.write(0.0,0.0,1.0);
                 ThisThread::sleep_for(50);
-                myRGBled(1.0,1.0,0.0);
+                myRGBled.write(1.0,1.0,0.0);
                 ThisThread::sleep_for(50);
             }
             current_item = rand() % 4 + 1;      //change this depending on items implemented and random item alg
-            if(current_item == 1){          //mushroom
-                myRGBled(1.0,0.0,0.0);
-            }
-            if(current_item == 2){          //green shell
-                myRGBled(0.0,1.0,0.0);
-            }
-            if(current_item == 3){          //blue shell
-                myRGBled(0.0,0.0,1.0);
-            }
-            if(current_item == 4){          //banana
-                myRGBled(1.0,1.0,0.0);
+            switch(current_item) {
+                case 1 : //mushroom
+                    myRGBled.write(1.0,0.0,0.0);
+                    break;
+                case 2 : //green shell
+                    myRGBled.write(0.0,1.0,0.0);
+                    break;
+                case 3 : //blue shell
+                    myRGBled.write(0.0,0.0,1.0);
+                    break;
+                case 4 : //banana
+                    myRGBled.write(1.0,1.0,0.0);
+                    break;
+                default :
+                    break;
             }
             itembox = false;
         }
@@ -207,7 +185,7 @@
     // Initialize Xbee and remote modules
     xbee.register_receive_cb(&receive_cb);
     RadioStatus const radioStatus = xbee.init();
-    const RemoteXBeeZB remoteDevice = RemoteXBeeZB(REMOTE_NODE_ADDR64);
+    const XBeeLib::RemoteXBee802 remoteDevice64b = RemoteXBee802(REMOTE_NODE_ADDR64);
     
     // Bluetooth controller code
     char bnum=0;