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: mbed motor MUSIC board Travel
Diff: main.cpp
- Revision:
- 6:eac1e6a55274
- Parent:
- 5:756dc04a891c
- Child:
- 7:a96163893291
--- a/main.cpp Fri Feb 14 14:34:04 2020 +0000
+++ b/main.cpp Fri Apr 03 15:02:43 2020 +0000
@@ -29,12 +29,12 @@
DigitalIn myButton(USER_BUTTON); //USER_BUTTON is the Blue Button on the NUCLEO Board
DigitalOut led(LED3); //LED1 is the Green LED on the NUCLEO board
- //N.B. The RED LED is the POWER Indicator
- //and the Multicoloured LED indicates status of the ST-LINK Programming cycle
+//N.B. The RED LED is the POWER Indicator
+//and the Multicoloured LED indicates status of the ST-LINK Programming cycle
Serial pc(USBTX,USBRX); //Instance of the Serial class to enable much faster BAUD rates then standard 9600 i.e. 115200
- //This is Pseudo RS232 over USB the NUCLEO will appear as a COMx Port see device Manager on PC used
- //Use PuTTY to monitor check COMx and BAUD rate (115200)
+//This is Pseudo RS232 over USB the NUCLEO will appear as a COMx Port see device Manager on PC used
+//Use PuTTY to monitor check COMx and BAUD rate (115200)
//Variable 'duty' for programmer to use to vary speed as required set here to #define compiler constant see above
@@ -42,58 +42,78 @@
//
int main ()
{
- pc.baud(9600); //BAUD Rate to 9600
- pc.printf("ROCO104 Demonstration Robot Buggy Plymouth University 2018/19\n\r");
+ pc.baud(9600); //BAUD Rate to 9600
+ pc.printf("ROCO104 Demonstration Robot Buggy Plymouth University 2018/19\n\r");
- Wheel.Period_in_ms(TIME_PERIOD);//Set frequency of the PWMs
+ Wheel.Period_in_ms(TIME_PERIOD);//Set frequency of the PWMs
- //
- //--------------------------- your strategy goes between the two dashed lines ---------------------------------------------
- //
+ //
+ //--------------------------- your strategy goes between the two dashed lines ---------------------------------------------
+ //
Wheel.Stop();
-
- close_encounter(1); //tune to play Announce start!
+
+ //close_encounter(1); //tune to play Announce start!
//twinkle(1); //see tunes.h for alternatives or make your own!
//jingle_bells(1);
-
- while(myButton==0)
- { //Wait here for USER Button (Blue) on Nucleo Board (goes to zero when pressed)
+ megolavania(1);
+ while(myButton==0) {
+ //Wait here for USER Button (Blue) on Nucleo Board (goes to zero when pressed)
led=0; //and flash green LED whilst waiting
wait(0.1);
- led=1;
+ led=1;
wait(0.1);
//Test Microswitches with two different tones see tunes.cpp tunes.h or flash (led1 and led2) onboard LEDs
-
+
}
-
- //Repeat the following forever NB always true!
+
+ //Repeat the following forever NB always true!
// YOUR LINES OF CODE for your stratagy go between HERE! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- Wheel.Period_in_ms(2);//Set frequency of the PWMs 500Hz
- while(true)
- {
- Wheel.Speed(0.8,0.8);//Forward 80%
- wait(5.0);
+ Wheel.Period_in_ms(2);//Set frequency of the PWMs 500Hz
+
+
+ while (true) {
+
+ while(microswitch1 == 0);
+ {
+ Wheel.Speed(0.8,0.8);
+ }
+
Wheel.Stop();
- wait(1.0);
- Wheel.Speed(-0.8,-0.8);//Reverse 80%
- wait(5.0);
- Wheel.Stop();
- wait(1.0);
+
+ while(microswitch2 == 0)
+ {
+ Wheel.Speed(-0.8,-0.8);
+ }
+
+ //turn right
+ Wheel.Speed(0.8,0.0);
+ wait(0.5);
+
+ //forward
+ Wheel.Speed(0.8,0.8);
+ wait(0.5);
+
+ //turn left
+ Wheel.Speed(0.0,0.8);
+ wait(0.5);
+
+
}
+
// and HERE! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- } // go back to start of while loop
- //end of int main()
+} // go back to start of while loop
+//end of int main()
/*
//Consider these lines of code to Accelerate the motors
for (float i=0.5f; i<=1.0f; i+=0.01f) //Accelerate from 50% to 100%
- {
+ {
Wheel.Speed(i,i);
wait(0.1f);
}