I am very frustrated. I've got several books and I thought I was following them. But I must not understand something basic. There are many errors in my code but latest says " Compilation error: " Leftdetect' does not name a type." I'm thinking, yes it does, bool! I typed and initialized it in Setup. So I put the variable in setup after I had declared it. Putting the computer's cursor over it the IDE displays a popup box the says it a Variable of type bool with a value of true, typed and initialized in setup. Yep, That's exactly what I did. Then I put the variable between setup and loop and dragged the cursor over it. Now it is type int, no value listed and it was typed in something called public. I don' t even know what public is, much less have used it. Then I put the variable in loop and the cursor also listed it as init, typed in public. Clearly something I don't understand here. I thought a variable typed in setup was typed everywhere and forever more. But no??? Here is my code.
// Today's date: 7/26/2024
// Line following code to operate L/R continous rotation servos and L/R IR line sensors
// Added routine for platform tilt 7/20/2024
// Less than 90 on left is CW on left continuous rotation servo motor.
// greater than 90 on right is CCW on right continuous rotation servo motor.
// 90 is stop on both motors. Adjust trim screw on servos for no motion at stop.
//
// Prototype Function Declarations for compiler. Full declartions later.
// void Straight () {};
// void Left() {};
// void Right() {};
// void No_movement() {};
//
#include <Servo.h>;
Servo Platform;
int N = 0;
// ************************* SETUP *****************************
void setup()
{
Servo LeftWheel;
Servo RightWheel;
bool Leftdetect = true;
bool Rightdetect = true;
pinMode(LED_BUILTIN, OUTPUT); // LED on when platform tilt servo is active.
// int Platform.attach(11);
pinMode(9, OUTPUT); // Left Wheel
pinMode(10, OUTPUT); // Right wheel
pinMode(11, OUTPUT); // Platform tilt
// Sensors
pinMode(6, INPUT); // Left Line sensor
pinMode(7, INPUT); // Right Line sensor
LeftWheel.attach(9);
RightWheel.attach(10);
// N is a Marker so we won't call no-motion repeatedly without motion first.
// because no-motion function also activates platform tilt action.
// Since We have never called it before it is initialized to 0.
int N = 0;
//
// END OF SETUP
Leftdetect;
};
// ************************ LØOP **************************
Leftdetect;
//
void loop(){};
leftdetect
//
// LOOP to read sensors and call appropriate movement functions.
//
//
// Read the Sensors.
Leftdetect=digitalRead(6);
Rightdetect = digitalRead(7);
//
// 1st test, call Straight if Line not seen in either left or right sensor
if ((Leftdetect = false) && (Rightdetect == false)) ;
{;
// We are about to do something other than stopping, Set Marker to 0.
N = 0;
Straight(); // Call straight Function
}; // Close 1st test: straight Line 49
//
// 2nd test. Line is seen only in left sensor. Remember False is the line.
if ((Leftdetect == false) && (Rightdetect == true)) {;
// (Tracking into line from left, Correct by turning left)
Left();
// We are doing something other than stopping, reset marker.
N = 0;
}; // Close 2nd Test. Left Turn.
//
// 3rd test. Line is seen only in Right sensor. Remember False is the line.
if ((Leftdetect == true) && (Rightdetect == false)) {;
// (Tracking into line from right, Correct by turning right)
Right();
// We are doing something other than stopping, reset marker.
N = 0;
}; // Close 3rd test. Right Turn. Line 64
//
// 4th test, No motion. Line sensed in both sensors, call Stop motion with Platorm tilt
//
if ((Leftdetect == true) && (Rightdetect == true)) {;
// Only proceed with No-movement/ Tilt Platform if marker has been reset
// to 0 saying we are coming from a movement function call.
if (N = 0) ;
// Proceed with No Movement function call and set the marker!
No_movement();
N=1 ;
//
} // Close 4th test. No Movement/platform tilt. Line 72
// ************ End Of Loop/main-program function. Line 41 *****************
//
}
//************************ FUNCTION DEFINITIONS ************************
// Movement Functions: Left side 90 counting up. Right side 90 counting down
// Straight function defination 0000000000
void Straight ()
{
LeftWheel.write(95); delay(50);
RightWheel.write(85); delay(50);
// Left - Stop position plus movement (90 + 5)
// Right - Stop position minus movement (90 - 5)
}; // Close straight function definition Line 85 0000000000
//
void Left ()
{ // Open Left function defination 0000000000
LeftWheel.write(90);delay(50);
RightWheel.write(85);delay(50);
// Left servo. No movement just Stop position (90)
// Right servo. Stop position minus movement (90 - 5)
}; // Close Left function definition Line 92 0000000000
void Right ()
{
LeftWheel.write(95);delay(50);
RightWheel.write(90);delay(50);
// Left servo. Stop position plus movement (90 + 5)
// Right servo No movement just Stop position (90)
}; // Close Right function definition Line 99
//
void No_movement ()
{
LeftWheel.write(90);delay(500);
RightWheel.write(90);delay(500);
// Left servo. Stop position (90)
// Right servo. Stop position (90)
// Tilt platform by activating the platform tilt servo
// Turn builtin LED on while platform is active.
// Platform.write(90);
digitalWrite(LED_BUILTIN, HIGH);
delay(5000);
// Lower the platform by again activating platform tilt servo
// Platform.write(0);
// delay(100);
// Turn builtin LED off after platform is lowered
digitalWrite(LED_BUILTIN, LOW);
} // Close No_movement
};