MRJJ / clickers

Dependents:   ROCO104_Buggy BuggyDesign

Committer:
Mikebob
Date:
Wed May 13 16:24:54 2020 +0000
Revision:
5:e32cc4bf5aac
Parent:
4:595e353826e5
Small update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mikebob 0:cfb1fcccadd6 1 #include "mbed.h"
Mikebob 0:cfb1fcccadd6 2 #include "motor.h"
Mikebob 0:cfb1fcccadd6 3 #include "clickers.h"
jakesmart 2:2571dd52276f 4 #include "UltraSonic.h"
Mikebob 0:cfb1fcccadd6 5
Mikebob 4:595e353826e5 6 //These externs allow variables and functiones to be used that in another folder/library
Mikebob 0:cfb1fcccadd6 7 extern DigitalIn microswitch1; //Instance of the DigitalIn class called 'microswitch1'
Mikebob 0:cfb1fcccadd6 8 extern DigitalIn microswitch2; //Instance of the DigitalIn class called 'microswitch2'
Mikebob 0:cfb1fcccadd6 9 extern Motor Wheel;
Mikebob 1:d5b76569b45c 10 extern Serial pc;
Mikebob 1:d5b76569b45c 11 extern int mm;
jakesmart 2:2571dd52276f 12 extern void dist();
jakesmart 2:2571dd52276f 13 extern bool rStopped, fStopped;
Mikebob 4:595e353826e5 14
Mikebob 4:595e353826e5 15 void RevStop()//This function will stop the buggy and change the bool to true to say the buggy has been stopped from going backwards
Mikebob 0:cfb1fcccadd6 16 {
Mikebob 3:91541ffdf9a5 17 if (microswitch1 == true)
Mikebob 0:cfb1fcccadd6 18 {
Mikebob 4:595e353826e5 19 microswitch1.read();//Read the state of the microswitch
Mikebob 5:e32cc4bf5aac 20 Wheel.Stop();//Stop wheels
Mikebob 4:595e353826e5 21 rStopped = true;//Change bool state to true
Mikebob 4:595e353826e5 22 dist();//Check distance
jakesmart 2:2571dd52276f 23 }
Mikebob 3:91541ffdf9a5 24 }
Mikebob 4:595e353826e5 25 void FwdStop()//This function will stop the buggy and change the bool to true to say the buggy has been stopped from going forwards
jakesmart 2:2571dd52276f 26 {
Mikebob 4:595e353826e5 27 if (mm<= 500)//Do the following if the buggy is less than 500mm to the edge of the arena
Mikebob 3:91541ffdf9a5 28 {
Mikebob 4:595e353826e5 29 Wheel.Stop();//Stop wheels
Mikebob 4:595e353826e5 30 fStopped = true;//Change bool state to true
Mikebob 4:595e353826e5 31 dist();//Check distance
Mikebob 3:91541ffdf9a5 32 }
Mikebob 3:91541ffdf9a5 33 else
Mikebob 3:91541ffdf9a5 34 {
Mikebob 4:595e353826e5 35
Mikebob 4:595e353826e5 36 fStopped = false; //Keep bool state false
Mikebob 4:595e353826e5 37 dist();//Check distance
Mikebob 0:cfb1fcccadd6 38 }
Mikebob 0:cfb1fcccadd6 39 }