Rachel Ireland-Jones / Mbed 2 deprecated BuggyDesign

Dependencies:   Movement mbed tunes motor pwm_tone clickers Ultra

Committer:
jaffacat
Date:
Tue Feb 16 18:11:19 2021 +0000
Revision:
16:9e039741a739
Parent:
15:f64e77f45a3d
C++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martinsimpson 0:51c12cc34baf 1 #include "mbed.h"
martinsimpson 0:51c12cc34baf 2 #include "motor.h"
jakesmart 9:1094da23254d 3 #include "UltraSonic.h"
martinsimpson 0:51c12cc34baf 4 #include "tunes.h"
Mikebob 5:a0090b8b327b 5 #include "clickers.h"
Mikebob 12:15272c2ae2ed 6 #include "Movement.h"
martinsimpson 0:51c12cc34baf 7 #define TIME_PERIOD 2 //Constant compiler Values here 2 equates to 2ms or 500Hz base Frequency
martinsimpson 0:51c12cc34baf 8 #define DUTY 0.9 //DUTY of 1.0=100%, 0.4=40% etc.,
martinsimpson 0:51c12cc34baf 9
martinsimpson 0:51c12cc34baf 10 DigitalIn microswitch1(D4); //Instance of the DigitalIn class called 'microswitch1'
martinsimpson 0:51c12cc34baf 11 DigitalIn microswitch2(D3); //Instance of the DigitalIn class called 'microswitch2'
Mikebob 7:48bf77d076fc 12 Motor Wheel(D13,D11,D9,D10); //Instance of the Motor Class called 'Wheel' see motor.h and motor.cpp
martinsimpson 0:51c12cc34baf 13 DigitalIn myButton(USER_BUTTON); //USER_BUTTON is the Blue Button on the NUCLEO Board
martinsimpson 1:3ca91ad8e927 14 DigitalOut led(LED3); //LED1 is the Green LED on the NUCLEO board
martinsimpson 0:51c12cc34baf 15 //N.B. The RED LED is the POWER Indicator
martinsimpson 0:51c12cc34baf 16 //and the Multicoloured LED indicates status of the ST-LINK Programming cycle
martinsimpson 0:51c12cc34baf 17
martinsimpson 0:51c12cc34baf 18 Serial pc(USBTX,USBRX); //Instance of the Serial class to enable much faster BAUD rates then standard 9600 i.e. 115200
martinsimpson 0:51c12cc34baf 19 //This is Pseudo RS232 over USB the NUCLEO will appear as a COMx Port see device Manager on PC used
martinsimpson 0:51c12cc34baf 20 //Use PuTTY to monitor check COMx and BAUD rate (115200)
Mikebob 13:13f14a8a902b 21 int mm; //This variable will hold the distance in mm between the buggy and the object infront of it
Mikebob 13:13f14a8a902b 22 bool fStopped, rStopped = false;// these variables are used to determine weather the buggy has been stopped, either from going forwards or backwards
Mikebob 13:13f14a8a902b 23
Mikebob 13:13f14a8a902b 24 void dist(){//This function will get the distance in mm and set the mm variable to this value
Mikebob 12:15272c2ae2ed 25 ultra_sonic_distance();
jakesmart 9:1094da23254d 26 mm = (int)GetDistance();
Mikebob 7:48bf77d076fc 27 }
martinsimpson 0:51c12cc34baf 28 int main ()
martinsimpson 0:51c12cc34baf 29 {
Mikebob 7:48bf77d076fc 30 pc.baud(9600); //BAUD Rate to 9600
Mikebob 7:48bf77d076fc 31 pc.printf("ROCO104 Demonstration Robot Buggy Plymouth University 2018/19\n\r");
Mikebob 7:48bf77d076fc 32 Wheel.Period_in_ms(TIME_PERIOD);//Set frequency of the PWMs
martinsimpson 1:3ca91ad8e927 33 Wheel.Stop();
martinsimpson 0:51c12cc34baf 34
martinsimpson 1:3ca91ad8e927 35 close_encounter(1); //tune to play Announce start!
martinsimpson 1:3ca91ad8e927 36 //twinkle(1); //see tunes.h for alternatives or make your own!
martinsimpson 1:3ca91ad8e927 37 //jingle_bells(1);
Mikebob 7:48bf77d076fc 38
martinsimpson 1:3ca91ad8e927 39 while(myButton==0)
martinsimpson 1:3ca91ad8e927 40 { //Wait here for USER Button (Blue) on Nucleo Board (goes to zero when pressed)
martinsimpson 1:3ca91ad8e927 41 led=0; //and flash green LED whilst waiting
martinsimpson 0:51c12cc34baf 42 wait(0.1);
martinsimpson 0:51c12cc34baf 43 led=1;
martinsimpson 0:51c12cc34baf 44 wait(0.1);
martinsimpson 4:8249fab4d8d3 45 //Test Microswitches with two different tones see tunes.cpp tunes.h or flash (led1 and led2) onboard LEDs
martinsimpson 0:51c12cc34baf 46 }
Mikebob 5:a0090b8b327b 47 Wheel.Period_in_ms(2);//Set frequency of the PWMs 500Hz
Mikebob 7:48bf77d076fc 48
martinsimpson 1:3ca91ad8e927 49 while(true) //Repeat the following forever NB always true!
martinsimpson 0:51c12cc34baf 50 {
Mikebob 13:13f14a8a902b 51 Direction();// run the Direction function in the Movement library
martinsimpson 4:8249fab4d8d3 52 } // go back to start of while loop
martinsimpson 4:8249fab4d8d3 53 } //end of int main()