Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q TSI mbed
Fork of snakecontroller by
Diff: main.cpp
- Revision:
- 6:44bac63d4d66
- Parent:
- 5:97c02241511c
- Child:
- 7:292f2de3c013
--- a/main.cpp Thu Jun 09 10:36:19 2016 +0000
+++ b/main.cpp Thu Jun 09 14:34:08 2016 +0000
@@ -6,14 +6,14 @@
Serial pc(USBTX, USBRX); // tx, rx
MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); //Setup accelerometer
-DigitalOut lefthigh(PTC11); //Test LED for left
-DigitalOut leftlow(PTC9);
-DigitalOut righthigh(PTC5); //Test LED for right
-DigitalOut rightlow(PTA4);
-DigitalOut forwardhigh(PTC16); //Test LED for forward
-DigitalOut forwardlow(PTD0);
-DigitalOut backwardhigh(PTA17); //Test LED for backward
-DigitalOut backwardlow(PTD1);
+DigitalOut lefthigh(PTC7); //Test LED for left
+DigitalOut leftlow(PTA1);
+DigitalOut righthigh(PTC4); //Test LED for right
+DigitalOut rightlow(PTA12);
+DigitalOut forwardhigh(PTC0); //Test LED for forward
+DigitalOut forwardlow(PTC3);
+DigitalOut backwardhigh(PTA2); //Test LED for backward
+DigitalOut backwardlow(PTD4);
float accX=acc.getAccX(); //Measure acceleration in X direction
float accY=acc.getAccY(); //Measure acceleration in Y direction
@@ -30,90 +30,30 @@
float accX=acc.getAccX(); //Measure acceleration in X direction
float accY=acc.getAccY(); //Measure acceleration in Y direction
-
- if((accX <= 0.1f) && (accX >= -0.1f))
- {
- if (right == false)
- {
- righthigh = 1;
- rightlow = 0;
- } //endif
- else
- {
- lefthigh = 1;
- leftlow = 0;
- }//endelse
- }//endif
-
+
if (accX > 0.1)
{
- lefthigh = 0;
- leftlow = 0;
- righthigh = 1;
- rightlow = 0;
- forwardhigh = 0;
- forwardlow = 0;
- backwardhigh = 0;
- backwardlow = 0;
right = false;
- printf("left \r\n");
+ //printf("left \r\n");
}//endif
if (accX < -0.1)
{
- lefthigh = 1;
- leftlow = 0;
- righthigh = 0;
- rightlow = 0;
- forwardhigh = 0;
- forwardlow = 0;
- backwardhigh = 0;
- backwardlow = 0;
right = true;
- printf("right \r\n");
+ //printf("right \r\n");
}//endif
wait(0.1);
- if((accY <= 0.1) && (accY >= -0.1))
- {
- if (forward == false)
- {
- forwardhigh = 1;
- forwardlow = 0;
- }//endif
- else
- {
- backwardhigh = 1;
- backwardlow = 0;
- }//endelse
- }//endif
-
if (accY > 0.1)
{
- lefthigh = 0;
- leftlow = 0;
- righthigh = 0;
- rightlow = 0;
- forwardhigh = 1;
- forwardlow = 0;
- backwardhigh = 0;
- backwardlow = 0;
forward = false;
- printf("back \r\n");
+ //printf("back \r\n");
}//endif
if (accY < -0.1)
{
- lefthigh = 0;
- leftlow = 0;
- righthigh = 0;
- rightlow = 0;
- forwardhigh = 0;
- forwardlow = 0;
- backwardhigh = 1;
- backwardlow = 0;
forward = true;
- printf("for \r\n");
+ //printf("for \r\n");
}//endif
wait(0.1);
@@ -123,21 +63,61 @@
if(forward == true)
{
Direction = 0;
+
+ lefthigh = 0;
+ leftlow = 0;
+ righthigh = 0;
+ rightlow = 0;
+ forwardhigh = 1;
+ forwardlow = 0;
+ backwardhigh = 0;
+ backwardlow = 0;
+
}//endif
else
{
- Direction = 2;
+ Direction = 2;
+
+ lefthigh = 0;
+ leftlow = 0;
+ righthigh = 0;
+ rightlow = 0;
+ forwardhigh = 0;
+ forwardlow = 0;
+ backwardhigh = 1;
+ backwardlow = 0;
+
}//endelse
}//endif
else
{
if(right == true)
{
- Direction = 1;
+ Direction = 1;
+
+ lefthigh = 0;
+ leftlow = 0;
+ righthigh = 1;
+ rightlow = 0;
+ forwardhigh = 0;
+ forwardlow = 0;
+ backwardhigh = 0;
+ backwardlow = 0;
+
}//endif
else
{
- Direction = 3;
+ Direction = 3;
+
+ lefthigh = 1;
+ leftlow = 0;
+ righthigh = 0;
+ rightlow = 0;
+ forwardhigh = 0;
+ forwardlow = 0;
+ backwardhigh = 0;
+ backwardlow = 0;
+
}//endelse
}//endelse
