BoeBot Shield for Arduino Question
I am learning as I go with the tutorials and I am at Chapter 4, Activity 4. Ramping. So I thought I understood. I used the samples to do the ramping for forward start, 3 seconds or whatever it was, then stop. No problem. So at the end of the tutorial it asks me to:
Sorry about the notes, I cut and paste most of it then just adjusted what I needed to. I will fix the notes once I get it right.
any help would be much appreciated. Thanx.
- Open the sketch ForwardLeftRightBackward and save it as ForwardLeftRightBackwardRamping.
- Modify the new sketch so your BOE Shield-Bot will ramp into and out of each maneuver. Hint: you might use the code snippets above, and similar snippets from StartAndStopWithRamping.
Sorry about the notes, I cut and paste most of it then just adjusted what I needed to. I will fix the notes once I get it right.
// Robotics with the BOE Shield - ForwardLeftRightBackwardRamping// Move forward, left, right, then backward for testing and tuning.
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servos
Servo servoRight;
void setup() // Built-in initialization block
{
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone
servoLeft.attach(13); // Attach left signal to P13
servoRight.attach(12); // Attach right signal to P12
// Full speed forward
for(int speed = 0; speed <= 100; speed += 2) // Ramp up to full speed.
{
servoLeft.writeMicroseconds(1500+speed); // us = 1500,1502,...1598,1600
servoRight.writeMicroseconds(1500-speed); // us = 1500,1498,...1402,1400
delay(20); // 20 ms at each speed
}
delay(1500); // Full speed for 1.5 seconds
for(int speed = 100; speed >= 0; speed -= 2) // Ramp from full speed to stop
{
servoLeft.writeMicroseconds(1500+speed); // us = 1600,1598,...1502,1500
servoRight.writeMicroseconds(1500-speed); // us = 1400,1402,...1498,1500
delay(20); // 20 ms at each speed
} // ...for 2 seconds
// Turn left in place
for(int speed = 0; speed <= 100; speed += 2) // Ramp stop to right turn
{
servoLeft.writeMicroseconds(1500-speed); // us = 1500,1502, 1508...1600
servoRight.writeMicroseconds(1500-speed); // us = 1500,1502, 1508...1600
delay(20); // 20 ms at each speed
}
for(int speed = 100; speed >= 0; speed -= 2)// right turn to stop
{
servoLeft.writeMicroseconds(1500-speed); // us = 1600,1598, 1597...1500
servoRight.writeMicroseconds(1500-speed); // us = 1600,1598, 1597...1500
delay(20); // 20 ms at each speed
} // ...for 0.6 seconds
// Turn right in place
for(int speed = 0; speed <= 100; speed += 2) // Ramp stop to right turn
{
servoLeft.writeMicroseconds(1500+speed); // us = 1500,1502, 1508...1600
servoRight.writeMicroseconds(1500+speed); // us = 1500,1502, 1508...1600
delay(20); // 20 ms at each speed
}
for(int speed = 100; speed >= 0; speed -= 2)// right turn to stop
{
servoLeft.writeMicroseconds(1500+speed); // us = 1600,1598, 1597...1500
servoRight.writeMicroseconds(1500+speed); // us = 1600,1598, 1597...1500
delay(20); // 20 ms at each speed
} // ...for 0.6 seconds
// Full speed backward
for(int speed = 0; speed <= 100; speed -= 2) // Ramp up to full speed.
{
servoLeft.writeMicroseconds(1500+speed); // us = 1500,1502,...1598,1600
servoRight.writeMicroseconds(1500-speed); // us = 1500,1498,...1402,1400
delay(20); // 20 ms at each speed
}
delay(1500); // Full speed for 1.5 seconds
for(int speed = -100; speed >= 0; speed += 2) // Ramp from full speed to stop
{
servoLeft.writeMicroseconds(1500+speed); // us = 1600,1598,...1502,1500
servoRight.writeMicroseconds(1500-speed); // us = 1400,1402,...1498,1500
delay(20); // 20 ms at each speed
} // ...for 2 seconds
servoLeft.detach(); // Stop sending servo signals
servoRight.detach();
}
void loop() // Main loop auto-repeats
{ // Empty, nothing needs repeating
}
any help would be much appreciated. Thanx.

Comments
for(int speed = -100; speed >= 0; speed += 2) // Ramp from full speed to stop
You are starting with a negative number so speed will fail the test. I think the loop will terminate right away. Try this instead :
for(int speed = -100; speed <= 0; speed += 2) // Ramp from full speed to stop
I do realize why my first try failed tho. This can't work.
Here's what did work:
.
// ForwardLeftRightBackwardRamping// Move forward, left, right, then backward for testing and tuning w/ ramping. #include <Servo.h> // Include servo library Servo servoLeft; // Declare left and right servos Servo servoRight; void setup() // Built-in initialization block { tone(4, 3000, 1000); // Play tone for 1 second delay(1000); // Delay to finish tone servoLeft.attach(13); // Attach left signal to P13 servoRight.attach(12); // Attach right signal to P12 // Full speed forward for(int speed = 0; speed <= 100; speed += 2) { servoLeft.writeMicroseconds(1500+speed); servoRight.writeMicroseconds(1500-speed); delay(20); } delay(1500); for(int speed = 100; speed >= 0; speed -= 2) { servoLeft.writeMicroseconds(1500+speed); servoRight.writeMicroseconds(1500-speed); delay(20); } // Turn left in place for(int speed = 0; speed <= 100; speed += 2) { servoLeft.writeMicroseconds(1500-speed); servoRight.writeMicroseconds(1500-speed); delay(20); } for(int speed = 100; speed >= 0; speed -= 2) { servoLeft.writeMicroseconds(1500-speed); servoRight.writeMicroseconds(1500-speed); delay(20); } // Turn right in place for(int speed = 0; speed <= 100; speed += 2) { servoLeft.writeMicroseconds(1500+speed); servoRight.writeMicroseconds(1500+speed); delay(20); } for(int speed = 100; speed >= 0; speed -= 2) { servoLeft.writeMicroseconds(1500+speed); servoRight.writeMicroseconds(1500+speed); delay(20); } // Full speed backward for(int speed = 0; speed <= 100; speed += 2) { servoLeft.writeMicroseconds(1500-speed); servoRight.writeMicroseconds(1500+speed); delay(20); } delay(1500); for(int speed = 100; speed >= 0; speed -= 2) { servoLeft.writeMicroseconds(1500-speed); servoRight.writeMicroseconds(1500+speed); delay(20); } servoLeft.detach(); servoRight.detach(); } void loop() { }