Skip to content

Commit d1cc622

Browse files
author
joeleb
committed
Updating code to V4.0a
Code corrections that accompany the SIK Errata sheet for V4.0 to V4.0a.
1 parent 2adc9b0 commit d1cc622

File tree

4 files changed

+77
-65
lines changed

4 files changed

+77
-65
lines changed

SIK_Circuit_3B-DistanceSensor/SIK_Circuit_3B-DistanceSensor.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/s
1111
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
1212
*/
1313

14-
const int echoPin = 13; //connects to the echo pin on the distance sensor
15-
const int trigPin = 12; //connects to the trigger pin on the distance sensor
14+
const int trigPin = 11; //connects to the echo pin on the distance sensor
15+
const int echoPin = 12; //connects to the trigger pin on the distance sensor
1616

1717
const int redPin = 3; //pin to control the red LED inside the RGB LED
1818
const int greenPin = 5; //pin to control the green LED inside the RGB LED

SIK_Circuit_5A-MotorBasics/SIK_Circuit_5A-MotorBasics.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
1313

1414
//PIN VARIABLES
1515
//the motor will be controlled by the motor A pins on the motor driver
16-
const int AIN1 = 11; //control pin 1 on the motor driver for the right motor
16+
const int AIN1 = 13; //control pin 1 on the motor driver for the right motor
1717
const int AIN2 = 12; //control pin 2 on the motor driver for the right motor
18-
const int PWMA = 13; //speed control pin on the motor driver for the right motor
18+
const int PWMA = 11; //speed control pin on the motor driver for the right motor
1919

2020
int switchPin = 7; //switch to turn the robot on and off
2121

SIK_Circuit_5B-RemoteControlRobot/SIK_Circuit_5B-RemoteControlRobot.ino

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/s
1414
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
1515
*/
1616

17-
//the left motor will be controlled by the motor B pins on the motor driver
18-
const int PWMB = 13; //speed control pin on the motor driver for the left motor
19-
const int BIN2 = 12; //control pin 2 on the motor driver for the left motor
20-
const int BIN1 = 11; //control pin 1 on the motor driver for the left motor
2117

2218
//the right motor will be controlled by the motor A pins on the motor driver
23-
const int AIN1 = 10; //control pin 1 on the motor driver for the right motor
24-
const int AIN2 = 9; //control pin 2 on the motor driver for the right motor
25-
const int PWMA = 8; //speed control pin on the motor driver for the right motor
19+
const int AIN1 = 13; //control pin 1 on the motor driver for the right motor
20+
const int AIN2 = 12; //control pin 2 on the motor driver for the right motor
21+
const int PWMA = 11; //speed control pin on the motor driver for the right motor
22+
23+
//the left motor will be controlled by the motor B pins on the motor driver
24+
const int PWMB = 10; //speed control pin on the motor driver for the left motor
25+
const int BIN2 = 9; //control pin 2 on the motor driver for the left motor
26+
const int BIN1 = 8; //control pin 1 on the motor driver for the left motor
27+
28+
int switchPin = 7; //switch to turn the robot on and off
2629

2730
const int driveTime = 20; //this is the number of milliseconds that it takes the robot to drive 1 inch
2831
//it is set so that if you tell the robot to drive forward 25 units, the robot drives about 25 inches
@@ -40,6 +43,8 @@ String distance; //the distance to travel in each direction
4043
/********************************************************************************/
4144
void setup()
4245
{
46+
pinMode(switchPin, INPUT_PULLUP); //set this as a pullup to sense whether the switch is flipped
47+
4348
//set the motor contro pins as outputs
4449
pinMode(AIN1, OUTPUT);
4550
pinMode(AIN2, OUTPUT);
@@ -48,7 +53,7 @@ void setup()
4853
pinMode(BIN1, OUTPUT);
4954
pinMode(BIN2, OUTPUT);
5055
pinMode(PWMB, OUTPUT);
51-
56+
5257
Serial.begin(9600); //begin serial communication with the computer
5358

5459
//prompt the user to enter a command
@@ -60,49 +65,57 @@ void setup()
6065
/********************************************************************************/
6166
void loop()
6267
{
63-
if (Serial.available() > 0) //if the user has sent a command to the RedBoard
64-
{
65-
botDirection = Serial.readStringUntil(' '); //read the characters in the command until you reach the first space
66-
distance = Serial.readStringUntil(' '); //read the characters in the command until yuo reach the second space
67-
68-
//print the command that was just received in the serial monitor
69-
Serial.print(botDirection);
70-
Serial.print(" ");
71-
Serial.println(distance.toInt());
72-
73-
if(botDirection == "f") //if the entered direction is forward
68+
if(digitalRead(7) == LOW)
69+
{ //if the switch is in the ON position
70+
if (Serial.available() > 0) //if the user has sent a command to the RedBoard
7471
{
75-
rightMotor(200); //drive the right wheel forward
76-
leftMotor(200); //drive the left wheel forward
77-
delay(driveTime * distance.toInt()); //drive the motors long enough travel the entered distance
78-
rightMotor(0); //turn the right motor off
79-
leftMotor(0); //turn the left motor off
80-
}
81-
else if(botDirection == "b") //if the entered direction is backward
82-
{
83-
rightMotor(-200); //drive the right wheel forward
84-
leftMotor(-200); //drive the left wheel forward
85-
delay(driveTime * distance.toInt()); //drive the motors long enough travel the entered distance
86-
rightMotor(0); //turn the right motor off
87-
leftMotor(0); //turn the left motor off
88-
}
89-
else if(botDirection == "l") //if the entered direction is right
90-
{
91-
rightMotor(-200); //drive the right wheel forward
92-
leftMotor(255); //drive the left wheel forward
93-
delay(turnTime * distance.toInt()); //drive the motors long enough turn the entered distance
94-
rightMotor(0); //turn the right motor off
95-
leftMotor(0); //turn the left motor off
96-
}
97-
else if(botDirection == "r") //if the entered direction is left
98-
{
99-
rightMotor(255); //drive the right wheel forward
100-
leftMotor(-200); //drive the left wheel forward
101-
delay(turnTime * distance.toInt()); //drive the motors long enough turn the entered distance
102-
rightMotor(0); //turn the right motor off
103-
leftMotor(0); //turn the left motor off
72+
botDirection = Serial.readStringUntil(' '); //read the characters in the command until you reach the first space
73+
distance = Serial.readStringUntil(' '); //read the characters in the command until yuo reach the second space
74+
75+
//print the command that was just received in the serial monitor
76+
Serial.print(botDirection);
77+
Serial.print(" ");
78+
Serial.println(distance.toInt());
79+
80+
if(botDirection == "f") //if the entered direction is forward
81+
{
82+
rightMotor(200); //drive the right wheel forward
83+
leftMotor(200); //drive the left wheel forward
84+
delay(driveTime * distance.toInt()); //drive the motors long enough travel the entered distance
85+
rightMotor(0); //turn the right motor off
86+
leftMotor(0); //turn the left motor off
87+
}
88+
else if(botDirection == "b") //if the entered direction is backward
89+
{
90+
rightMotor(-200); //drive the right wheel forward
91+
leftMotor(-200); //drive the left wheel forward
92+
delay(driveTime * distance.toInt()); //drive the motors long enough travel the entered distance
93+
rightMotor(0); //turn the right motor off
94+
leftMotor(0); //turn the left motor off
95+
}
96+
else if(botDirection == "r") //if the entered direction is right
97+
{
98+
rightMotor(-200); //drive the right wheel forward
99+
leftMotor(255); //drive the left wheel forward
100+
delay(turnTime * distance.toInt()); //drive the motors long enough turn the entered distance
101+
rightMotor(0); //turn the right motor off
102+
leftMotor(0); //turn the left motor off
103+
}
104+
else if(botDirection == "l") //if the entered direction is left
105+
{
106+
rightMotor(255); //drive the right wheel forward
107+
leftMotor(-200); //drive the left wheel forward
108+
delay(turnTime * distance.toInt()); //drive the motors long enough turn the entered distance
109+
rightMotor(0); //turn the right motor off
110+
leftMotor(0); //turn the left motor off
111+
}
104112
}
105113
}
114+
else
115+
{
116+
rightMotor(0); //turn the right motor off
117+
leftMotor(0); //turn the left motor off
118+
}
106119
}
107120
/********************************************************************************/
108121
void rightMotor(int motorSpeed) //function for driving the right motor

SIK_Circuit_5C-AutonomousRobot/SIK_Circuit_5C-AutonomousRobot.ino

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@ View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/s
1414
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
1515
*/
1616

17-
//distance variables
1817

19-
const int trigPin = 6;
20-
const int echoPin = 5;
2118

19+
//the right motor will be controlled by the motor A pins on the motor driver
20+
const int AIN1 = 13; //control pin 1 on the motor driver for the right motor
21+
const int AIN2 = 12; //control pin 2 on the motor driver for the right motor
22+
const int PWMA = 11; //speed control pin on the motor driver for the right motor
2223

2324
//the left motor will be controlled by the motor B pins on the motor driver
24-
const int PWMB = 8; //speed control pin on the motor driver for the left motor
25+
const int PWMB = 10; //speed control pin on the motor driver for the left motor
2526
const int BIN2 = 9; //control pin 2 on the motor driver for the left motor
26-
const int BIN1 = 10; //control pin 1 on the motor driver for the left motor
27-
28-
//the right motor will be controlled by the motor A pins on the motor driver
29-
const int AIN1 = 11; //control pin 1 on the motor driver for the right motor
30-
const int AIN2 = 12; //control pin 2 on the motor driver for the right motor
31-
const int PWMA = 13; //speed control pin on the motor driver for the right motor
27+
const int BIN1 = 8; //control pin 1 on the motor driver for the left motor
3228

3329

30+
//distance variables
31+
const int trigPin = 6;
32+
const int echoPin = 5;
3433

3534
int switchPin = 7; //switch to turn the robot on and off
3635

@@ -89,9 +88,9 @@ void loop()
8988
leftMotor(-255);
9089
delay(backupTime);
9190

92-
//turn to the right
93-
rightMotor(-255);
94-
leftMotor(255);
91+
//turn away from obsticle
92+
rightMotor(255);
93+
leftMotor(-255);
9594
delay(turnTime);
9695

9796
}else{ //if no obstacle is detected drive forward

0 commit comments

Comments
 (0)