Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //These switches are ordered from left to right when the bot is facing away from you. SWL1 = First switch on the left side.
- //#define takes up less room than const int
- const int swL1=0; //This and the next three switches need pin numbers, but I am leaving them at 0 until I can ask Kyle my questions
- const int swL2=0;
- const int swR1=0;
- const int swR2=0;
- const int ENB=5; //Enable side B
- const int ENA=6; //Enable side A
- const int IN1=11; //Init #1
- const int IN2=9; //Init #2
- const int IN3=8; //Init #3
- const int IN4=7; //Init #4
- //IN1-IN4 I reversed the pin numbers, because that is how they are shown on the board.
- //Variable Integers:
- int brushSpeed=0; //The speed of the brush
- //New Functions:
- void blockageLeft() { //In the event of an object blocking the robot's path on the left side
- }
- void blockageRight() { //In the event of an object blocking the robot's path on the right side
- }
- void lTurn(int speed,int length) { //Turn left
- digitalWrite(IN1,HIGH);
- digitalWrite(IN2,LOW);
- digitalWrite(IN3,HIGH);
- digitalWrite(IN4,LOW);
- analogWrite(ENB, speed);
- delay(length);
- }
- void rTurn(int speed,int length) { //Turn right
- digitalWrite(IN1,LOW);
- digitalWrite(IN2,HIGH);
- digitalWrite(IN3,LOW);
- digitalWrite(IN4,HIGH);
- analogWrite(ENA, speed);
- delay(length);
- }
- void fDrive(int speed,int length) { //Drive forwards
- digitalWrite(IN1,HIGH);
- digitalWrite(IN2,LOW);
- digitalWrite(IN3,LOW);
- digitalWrite(IN4,HIGH);
- analogWrite(ENA,speed);
- analogWrite(ENB,speed);
- delay(length);
- }
- void bDrive(int speed,int length) { //Drive backwards
- digitalWrite(IN1,LOW);
- digitalWrite(IN2,HIGH);
- digitalWrite(IN3,HIGH);
- digitalWrite(IN4,LOW);
- analogWrite(ENA,speed);
- analogWrite(ENB,speed);
- delay(length);
- }
- void setup() {
- Serial.begin(9600);
- //To declare each pin an input or output
- pinMode(IN1,OUTPUT);
- pinMode(IN2,OUTPUT);
- pinMode(IN3,OUTPUT);
- pinMode(IN4,OUTPUT);
- pinMode(ENA,OUTPUT);
- pinMode(ENB,OUTPUT);
- }
- void loop() {
- lTurn(255,5000); //I want this command...
- analogWrite(ENB, 255); //...To do the same things this and the next three things are doing.
- digitalWrite(IN1, HIGH);
- digitalWrite(IN2, LOW);
- delay(5000);
- /*But neither of these two pieces of code work properly; when I try a code that was
- written for this board, it does not work either. yet I have wired all the motors
- and the board as shown.*/
- }
- /* Here is what the code from the kit tells me to enter:
- (For Rotation of the left motors):
- //www.elegoo.com
- // Left motor truth table
- //Here are some handy tables to show the various modes of operation.
- // ENB IN1 IN2 Description
- // LOW Not Applicable Not Applicable Motor is off
- // HIGH LOW LOW Motor is stopped (brakes)
- // HIGH HIGH LOW Motor is on and turning forwards
- // HIGH LOW HIGH Motor is on and turning backwards
- // HIGH HIGH HIGH Motor is stopped (brakes)
- // define IO pin
- #define ENB 5
- #define IN1 7
- #define IN2 8
- //init the car
- void setup() {
- pinMode(IN1, OUTPUT); //set IO pin mode OUTPUT
- pinMode(IN2, OUTPUT);
- pinMode(ENB, OUTPUT);
- digitalWrite(ENB, HIGH); //Enable left motor
- }
- //mian loop
- void loop() {
- digitalWrite(IN1, HIGH);
- digitalWrite(IN2, LOW); //Right wheel turning forwards
- delay(1000); //delay 500ms
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, LOW); //Right wheel stoped
- delay(1000);
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, HIGH); //Right wheel turning backwards
- delay(1000);
- digitalWrite(IN1, HIGH);
- digitalWrite(IN2, HIGH); //Right wheel stoped
- delay(1000);
- }
- This was just for the left motors, the right motors are similar.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement