Bead pushing buggy
Dependencies: Movement mbed tunes motor pwm_tone clickers Ultra
main.cpp
00001 #include "mbed.h" 00002 #include "motor.h" 00003 #include "UltraSonic.h" 00004 #include "tunes.h" 00005 #include "clickers.h" 00006 #include "Movement.h" 00007 #define TIME_PERIOD 2 //Constant compiler Values here 2 equates to 2ms or 500Hz base Frequency 00008 #define DUTY 0.9 //DUTY of 1.0=100%, 0.4=40% etc., 00009 00010 DigitalIn microswitch1(D4); //Instance of the DigitalIn class called 'microswitch1' 00011 DigitalIn microswitch2(D3); //Instance of the DigitalIn class called 'microswitch2' 00012 Motor Wheel(D13,D11,D9,D10); //Instance of the Motor Class called 'Wheel' see motor.h and motor.cpp 00013 DigitalIn myButton(USER_BUTTON); //USER_BUTTON is the Blue Button on the NUCLEO Board 00014 DigitalOut led(LED3); //LED1 is the Green LED on the NUCLEO board 00015 //N.B. The RED LED is the POWER Indicator 00016 //and the Multicoloured LED indicates status of the ST-LINK Programming cycle 00017 00018 Serial pc(USBTX,USBRX); //Instance of the Serial class to enable much faster BAUD rates then standard 9600 i.e. 115200 00019 //This is Pseudo RS232 over USB the NUCLEO will appear as a COMx Port see device Manager on PC used 00020 //Use PuTTY to monitor check COMx and BAUD rate (115200) 00021 int mm; //This variable will hold the distance in mm between the buggy and the object infront of it 00022 bool fStopped, rStopped = false;// these variables are used to determine weather the buggy has been stopped, either from going forwards or backwards 00023 00024 void dist(){//This function will get the distance in mm and set the mm variable to this value 00025 ultra_sonic_distance(); 00026 mm = (int)GetDistance(); 00027 } 00028 int main () 00029 { 00030 pc.baud(9600); //BAUD Rate to 9600 00031 pc.printf("ROCO104 Demonstration Robot Buggy Plymouth University 2018/19\n\r"); 00032 Wheel.Period_in_ms(TIME_PERIOD);//Set frequency of the PWMs 00033 Wheel.Stop(); 00034 00035 close_encounter(1); //tune to play Announce start! 00036 //twinkle(1); //see tunes.h for alternatives or make your own! 00037 //jingle_bells(1); 00038 00039 while(myButton==0) 00040 { //Wait here for USER Button (Blue) on Nucleo Board (goes to zero when pressed) 00041 led=0; //and flash green LED whilst waiting 00042 wait(0.1); 00043 led=1; 00044 wait(0.1); 00045 //Test Microswitches with two different tones see tunes.cpp tunes.h or flash (led1 and led2) onboard LEDs 00046 } 00047 Wheel.Period_in_ms(2);//Set frequency of the PWMs 500Hz 00048 00049 while(true) //Repeat the following forever NB always true! 00050 { 00051 Direction();// run the Direction function in the Movement library 00052 } // go back to start of while loop 00053 } //end of int main()
Generated on Sun Jul 17 2022 15:12:19 by
1.7.2