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.
main.cpp
00001 /* 00002 Simple Routine for Nucleo Board for ROCO104 Buggy Motor Control and Microswitches 00003 Heavy edit from previous ROCO103PP code 00004 Motor Class can now be instansiated with all four pins needed to control the H Bridge 00005 with a member functions as follows 00006 00007 Motor::Speed(float A, Float B) range -0.1 to +1.0 to give full reverse to full forward for A/B motors 00008 Motor::Stop() STOP 00009 Motor::Fwd(float) Forward but floating point number (range 0.0 to 1.0) 00010 Motor::Rev(float) Reverse but floating point number (range 0.0 to 1.0) 00011 00012 Plymouth University 00013 M.Simpson 31st October 2016 00014 Edited 03/02/2017 00015 Edited 06/12/2018 00016 */ 00017 #include "mbed.h" 00018 #include "motor.h" 00019 #include "tunes.h" 00020 00021 #define TIME_PERIOD 2 //Constant compiler Values here 2 equates to 2ms or 500Hz base Frequency 00022 #define DUTY 0.9 //DUTY of 1.0=100%, 0.4=40% etc., 00023 00024 DigitalIn microswitch1(D4); //Instance of the DigitalIn class called 'microswitch1' 00025 DigitalIn microswitch2(D3); //Instance of the DigitalIn class called 'microswitch2' 00026 00027 Motor Wheel(D13,D11,D9,D10); //Instance of the Motor Class called 'Wheel' see motor.h and motor.cpp 00028 00029 DigitalIn myButton(USER_BUTTON); //USER_BUTTON is the Blue Button on the NUCLEO Board 00030 00031 DigitalOut led(LED3); //LED1 is the Green LED on the NUCLEO board 00032 //N.B. The RED LED is the POWER Indicator 00033 //and the Multicoloured LED indicates status of the ST-LINK Programming cycle 00034 00035 Serial pc(USBTX,USBRX); //Instance of the Serial class to enable much faster BAUD rates then standard 9600 i.e. 115200 00036 //This is Pseudo RS232 over USB the NUCLEO will appear as a COMx Port see device Manager on PC used 00037 //Use PuTTY to monitor check COMx and BAUD rate (115200) 00038 00039 00040 //Variable 'duty' for programmer to use to vary speed as required set here to #define compiler constant see above 00041 float duty=DUTY; 00042 // 00043 int main () 00044 { 00045 pc.baud(9600); //BAUD Rate to 9600 00046 pc.printf("ROCO104 Demonstration Robot Buggy Plymouth University 2018/19\n\r"); 00047 00048 Wheel.Period_in_ms(TIME_PERIOD);//Set frequency of the PWMs 00049 00050 // 00051 //--------------------------- your strategy goes between the two dashed lines --------------------------------------------- 00052 // 00053 Wheel.Stop(); 00054 00055 close_encounter(1); //tune to play Announce start! 00056 //twinkle(1); //see tunes.h for alternatives or make your own! 00057 //jingle_bells(1); 00058 00059 while(myButton==0) 00060 { //Wait here for USER Button (Blue) on Nucleo Board (goes to zero when pressed) 00061 led=0; //and flash green LED whilst waiting 00062 wait(0.1); 00063 led=1; 00064 wait(0.1); 00065 //Test Microswitches with two different tones see tunes.cpp tunes.h or flash (led1 and led2) onboard LEDs 00066 00067 } 00068 00069 while(true) //Repeat the following forever NB always true! 00070 { 00071 // YOUR LINES OF CODE for your stratagy go between HERE! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00072 // Remember to use plenty of comments by using:- 00073 00074 // Single line 00075 00076 /* 00077 multiple 00078 lines 00079 */ 00080 00081 00082 00083 00084 // and HERE! +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00085 } // go back to start of while loop 00086 } //end of int main() 00087 00088 00089 00090 /* 00091 //Consider these lines of code to Accelerate the motors 00092 for (float i=0.5f; i<=1.0f; i+=0.01f) //Accelerate from 50% to 100% 00093 { 00094 Wheel.Speed(i,i); 00095 wait(0.1f); 00096 } 00097 */
Generated on Tue Jul 12 2022 12:20:40 by
1.7.2