The Error Code is:exit status 1
expected unqualified-id before '{' token
#include <AccelStepper.h>
#define motorPin1 8 // IN1 pin on the ULN2003A driver
#define motorPin2 9 // IN2 pin on the ULN2003A driver
#define motorPin3 10 // IN3 pin on the ULN2003A driver
#define motorPin4 11 // IN4 pin on the ULN2003A driver
int stepsPerRevolution = 64; // steps per revolution
float degreePerRevolution = 5.625; // degree per revolution
AccelStepper stepper(AccelStepper::HALF4WIRE, motorPin1, motorPin3, motorPin2, motorPin4);
unsigned long previousMillis = 0; // Previous millis
unsigned long elapsedMillis = 0; // Elapesed millis since touch
int ledState = LOW; // Current LED state
int debounceTime = 1000; // Debounce time for the touch sensor
void setup() {
Serial.begin(9600); // initialise the serial monitor
stepper.setMaxSpeed(1000.0); // set the max motor speed
stepper.setAcceleration(100.0); // set the acceleration
stepper.setSpeed(200); // set the current speed
}
// Degrees of the momevement. So first to 30 degrees, then to -30 graden then to 60 degrees etc.
int steps[] = { 30, -30, 60, -60, 0 };
// The total entries in steps[]
int stepsCount = 5;
// Keeps track of the position in steps[] we are about to run
int stepsIndex = 0;
{
pinMode(7, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
// If the stepper isn't moving and doesn't have to go any distance
if (!stepper.isRunning() && stepper.distanceToGo() == 0) {
// Move the stepper to the degrees on the position of stepIndex in steps[]
stepper.moveTo(degToSteps(steps[stepsIndex]));
// Increase the index when the movement has been finished
stepsIndex++;
// If we have executed all positions of steps[]
if (stepsIndex > stepsCount) {
// Set the index to 0 and start all over again
stepsIndex = 0;
}
}
stepper.run();
}
/*
Converts degrees to steps
28BYJ-48 motor has 5.625 degrees per step
360 degrees / 5.625 = 64 steps per revolution
Example with degToSteps(45):
(64 / 5.625) * 45 = 512 steps
*/
float degToSteps(float deg) {
return (stepsPerRevolution / degreePerRevolution) * deg;
}
}
// Calculate the elapsed seconds
elapsedMillis = millis() - previousMillis;
// If the sensor is touched AND
// the elapsed time is larger than the given debounce time
if (digitalRead(8) == HIGH && elapsedMillis > debounceTime) {
// Set ledState to LOW if it was HIGH and vice versa
if (ledState == HIGH) {
ledState = LOW;
} else {
ledState = HIGH;
}
// send ledState to the builtin LED
digitalWrite(LED_BUILTIN, ledState);
// Store the current millis on the previous millis
previousMillis = millis();
}
I don't speak english - the text is translated with deepl.
If you format the code with CTRL-T, you will see your errors almost by yourself.
I use a customized formatting and with me it looks like this after CTRL-T:
#include <AccelStepper.h>
#define motorPin1 8 // IN1 pin on the ULN2003A driver
#define motorPin2 9 // IN2 pin on the ULN2003A driver
#define motorPin3 10 // IN3 pin on the ULN2003A driver
#define motorPin4 11 // IN4 pin on the ULN2003A driver
int stepsPerRevolution = 64; // steps per revolution
float degreePerRevolution = 5.625; // degree per revolution
AccelStepper stepper(AccelStepper::HALF4WIRE, motorPin1, motorPin3, motorPin2, motorPin4);
unsigned long previousMillis = 0; // Previous millis
unsigned long elapsedMillis = 0; // Elapesed millis since touch
int ledState = LOW; // Current LED state
int debounceTime = 1000; // Debounce time for the touch sensor
void setup()
{
Serial.begin(9600); // initialise the serial monitor
stepper.setMaxSpeed(1000.0); // set the max motor speed
stepper.setAcceleration(100.0); // set the acceleration
stepper.setSpeed(200); // set the current speed
}
// Degrees of the momevement. So first to 30 degrees, then to -30 graden then to 60 degrees etc.
int steps[] = { 30, -30, 60, -60, 0 };
// The total entries in steps[]
int stepsCount = 5;
// Keeps track of the position in steps[] we are about to run
int stepsIndex = 0;
{
pinMode(7, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop()
{
// If the stepper isn't moving and doesn't have to go any distance
if (!stepper.isRunning() && stepper.distanceToGo() == 0)
{
// Move the stepper to the degrees on the position of stepIndex in steps[]
stepper.moveTo(degToSteps(steps[stepsIndex]));
// Increase the index when the movement has been finished
stepsIndex++;
// If we have executed all positions of steps[]
if (stepsIndex > stepsCount)
{
// Set the index to 0 and start all over again
stepsIndex = 0;
}
}
stepper.run();
}
/*
Converts degrees to steps
28BYJ-48 motor has 5.625 degrees per step
360 degrees / 5.625 = 64 steps per revolution
Example with degToSteps(45):
(64 / 5.625) * 45 = 512 steps
*/
float degToSteps(float deg)
{
return (stepsPerRevolution / degreePerRevolution) * deg;
}
}
// Calculate the elapsed seconds
elapsedMillis = millis() - previousMillis;
// If the sensor is touched AND
// the elapsed time is larger than the given debounce time
if (digitalRead(8) == HIGH && elapsedMillis > debounceTime)
{
// Set ledState to LOW if it was HIGH and vice versa
if (ledState == HIGH)
{
ledState = LOW;
}
else
{
ledState = HIGH;
}
// send ledState to the builtin LED
digitalWrite(LED_BUILTIN, ledState);
// Store the current millis on the previous millis
previousMillis = millis();
}
is outside of a function. This belongs in the setup. Without brackets.
Here:
float degToSteps(float deg)
{
return (stepsPerRevolution / degreePerRevolution) * deg;
}
}
// Calculate the elapsed seconds
elapsedMillis = millis() - previousMillis;
// If the sensor is touched AND
// the elapsed time is larger than the given debounce time
if (digitalRead(8) == HIGH && elapsedMillis > debounceTime)
{
// Set ledState to LOW if it was HIGH and vice versa
if (ledState == HIGH)
{
ledState = LOW;
}
else
{
ledState = HIGH;
}
// send ledState to the builtin LED
digitalWrite(LED_BUILTIN, ledState);
// Store the current millis on the previous millis
previousMillis = millis();
}
one closing bracket "}" is too much.
The whole part from // Calculate the elapsed seconds is also outside a function.
If this is sorted correctly, then it should compile.
in this line: elapsedMillis = millis() - previousMillis;
it shows the error code: exit status 1
'elapsedMillis' does not name a type... what do I have to do
looks lke this block of code delimited by the braces "{", "}" is outside any function definition
and again near the bottom.
there's also that extra closing brace, "}"
not sure what the code is intended to do. it's better to build the code up in stages, a little at a time, testing each change, making sure it compiles and that it does what is expected