The Bumper Switch Robot
|
Recorded by HTC One M8
|
At first, I programmed a program for the robot, which could drive it to the library and hit Ms. Watt's desk.
One week later, we added a bumper switch sensor on the front of the robot, which could detect impact at the front of the robot and continue to work.
Those codes were programmed on EasyC V4 for Cortex with version 4.22 configuration.
.
One week later, we added a bumper switch sensor on the front of the robot, which could detect impact at the front of the robot and continue to work.
Those codes were programmed on EasyC V4 for Cortex with version 4.22 configuration.
.
The Fixed ProgramMain
#include "Main.h" void main ( void ) { int bumper; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 1500 ) ; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , -127 ) ; Wait ( 580 ) ; --------------------------------------------------------------------------------------------- SetMotor ( 1 , -101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 4000 ) ; SetMotor ( 1 , 101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 550 ) ; --------------------------------------------------------------------------------------------- SetMotor ( 1 , -98 ) ; SetMotor ( 10 , 127 ) ; Wait ( 9200 ) ; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , -127 ) ; Wait ( 540 ) ; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 3800 ) ; SetMotor ( 1 , 101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 580 ) ; --------------------------------------------------------------------------------------------- SetMotor ( 1 , -98 ) ; SetMotor ( 10 , 127 ) ; Wait ( 9200 ) ; SetMotor ( 1 , -80 ) ; SetMotor ( 10 , 127 ) ; Wait ( 2000 ) ; } |
The Bumper Switch OneMain
#include "Main.h" void main ( void ) { int bumper; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 1500 ) ; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , -127 ) ; Wait ( 580 ) ; --------------------------------------------------------------------------------------------- while ( 1==1 ) { bumper = GetDigitalInput ( 1 ) ; if ( bumper==1 ) { SetMotor ( 1 , -98 ) ; SetMotor ( 10 , 127 ) ; } else { break ; } } SetMotor ( 1 , 101 ) ; SetMotor ( 10 , -127 ) ; Wait ( 2000 ) ; SetMotor ( 1 , 101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 550 ) ; --------------------------------------------------------------------------------------------- SetMotor ( 1 , -98 ) ; SetMotor ( 10 , 127 ) ; Wait ( 9200 ) ; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , -127 ) ; Wait ( 540 ) ; SetMotor ( 1 , -101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 3800 ) ; SetMotor ( 1 , 101 ) ; SetMotor ( 10 , 127 ) ; Wait ( 580 ) ; --------------------------------------------------------------------------------------------- while ( 1==1 ) { bumper = GetDigitalInput ( 1 ) ; if ( bumper==1 ) { SetMotor ( 1 , -80 ) ; SetMotor ( 10 , 127 ) ; } else { SetMotor ( 1 , 0 ) ; SetMotor ( 10 , 0 ) ; break ; } } } |