I am using the Arduino IDE to create programs for the Tetrix Prizm Robotics controller based on the Arduino Genuino Uno and the code is not executing as expected. I have included the code below. In the void loop i have a series of statements that send the robot forward at 50% motor power and then call a function to use the sonar sensor to check distance and execute another function to turn and then My intent is for it to return to the void loop and continue to run the statements until complete.
#include <PRIZM.h> // include PRIZM library
PRIZM prizm; // instantiate a PRIZM object “prizm” so we can use its functions
void pauseR();
void pauseL();
void rightTurn();
void leftTurn();
void setup() {
prizm.PrizmBegin(); // initialize PRIZM
prizm.setMotorInvert(1, 1); // invert the direction of DC Motor 1 to harmonize direction
}
void loop() {
prizm.setMotorPowers(50, 50);
pauseL();
prizm.setMotorPowers(50, 50);
pauseR();
prizm.setMotorPowers(50, 50);
pauseR();
prizm.setMotorPowers(50, 50);
pauseL();
}
void pauseR() { //pause robot and turn right
while (prizm.readSonicSensorCM(4) < 25)
{
prizm.setMotorPowers(125, 125); // stop both motors with in brake mode
rightTurn();
}
}
void pauseL() {
while (prizm.readSonicSensorCM(4) < 25)
{
prizm.setMotorPowers(125, 125); // stop both motors with in brake mode
leftTurn();
}
}
void rightTurn() { // function for a right turn
prizm.setMotorPowers(-50, 50); // make a right turn
delay(600); // wait here for .6 seconds while motors spin
prizm.setMotorPowers(125, 125); // stop both motors with in brake mode
delay(1000); // wait here for 1 second
return;
}
void leftTurn() { // function for a right turn
prizm.setMotorPowers(50, -50); // make a right turn
delay(600); // wait here for .6 seconds while motors spin
prizm.setMotorPowers(125, 125); // stop both motors with in brake mode
delay(1000); // wait here for 1 second
return;
}