Hi, I’ve recently received a Makeblock Starter Robot Kit (Bluetooth Version). This is the Ultrasonic tank/trike, programmable in Arduino. The board is a Makeblock Orion, or Arduino Uno. While not being new to programming, I have only started with Arduino and these simple robotics.
After teaching myself through some example programs and help online, I began to write my own program as a tutorial or learning crutch for myself. Having followed a working example program, I came across unexpected errors upon verification/compilation. I am unable to find what is wrong, and any help would be greatly appreciated!
My code:
// Include, or import, library functions
#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
// Declare variables and port connections
MeDCMotor MotorL(M1);
MeDCMotor MotorR(M2);
MeUltrasonicSensor UltrasonicSensor(PORT_3); // Points program to port 3
int moveSpeed = 200; // Motor movement speed/torque
int distance = 0; // Distance, in cm, detected by Ultrasonic Sensor
int randNum = 0; // Random number for turns
boolean leftTurn, rightTurn; // Tags for right and left turns
// Setup contains all code that will execute on startup
void setup()
{
leftTurn = false;
rightTurn = false;
randomSeed(analogRead(0)); // Begins random number generator
Serial.begin(9600); // Allows serial communication with computer
// Gives a startup 'heartbeat'
buzzerOn();
delay(50);
buzzerOff();
delay(150);
buzzerOn();
delay(50);
buzzerOff();
}
// Loop contains all code that will execute repeatedly
void loop()
{
distance = UltrasonicSensor.distanceCm(); // Sensor reads distance in cm
Serial.println(distance); // Print line of distance variable to serial output
if((distance > 2) && (distance < 40)) // Activate when distance < 40cm
{
randNum = random(100); // Generate random number up to 100
if((randNum > 50) && (!leftTurn)) // If randNum > 50 and leftTurn = false
{
rightTurn = true; // Enable rightTurn
TurnRight(); // Execute TurnRight function
}
else
{
leftTurn = true;
TurnLeft(); // TurnLeft function
}
}
else
{
rightTurn = false; // Disable rightTurn
leftTurn = false; // Disable leftTurn
Forward(); // Forward function
}
delay(250); // Delay .25 seconds
}
void Forward(); // Enable both motors to run forward
{
MotorL.run(moveSpeed); // MotorL run at moveSpeed speed
MotorR.run(moveSpeed); // MotorR run at moveSpeed speed
}
void TurnLeft();
{
MotorL.run(moveSpeed);
MotorR.run(-moveSpeed);
}
void TurnRight();
{
MotorL.run(-moveSpeed);
MotorR.run(moveSpeed);
}
And the errors:
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
Robotics_Trike.ino: In function 'void loop()':
Robotics_Trike:55: error: 'TurnRight' was not declared in this scope
Robotics_Trike:60: error: 'TurnLeft' was not declared in this scope
Robotics_Trike:67: error: 'Forward' was not declared in this scope
Robotics_Trike.ino: At global scope:
Robotics_Trike:73: error: expected unqualified-id before '{' token
Robotics_Trike:79: error: expected unqualified-id before '{' token
Robotics_Trike:85: error: expected unqualified-id before '{' token