79602483

Date: 2025-05-01 20:24:41
Score: 1
Natty:
Report link

I'm struggling with my Arduino Project Called TolBooth. I'm getting an error that says Function definition is not allowed here on lines on 86:17, and 114:20.

#include <Servo.h>

const int buttonPin = 8;
const int limitUpPin = 3;
const int limitDownPin = 4;
const int blueLEDPin = 10;
const int redLEDPin = 9;
const int servoPin = 5;
const int echoPin = 2;
const int trigPin = 3;
const int echoPin2 = 11;
const int trigPin2 = 12;

float duration = 0.0;
float distance = 0.0;

Servo tollArm;

bool armUp = false;
bool armDown = true;
bool moving = false;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(limitUpPin, INPUT_PULLUP);
pinMode(limitDownPin, INPUT_PULLUP);
pinMode(blueLEDPin, OUTPUT);
pinMode(redLEDPin, OUTPUT);
tollArm.attach(servoPin);
tollArm.write(0); // Start with arm down (0 degrees)

digitalWrite(blueLEDPin, LOW);
digitalWrite(redLEDPin, HIGH); // Arm is down initially
}

float checkDistance(){
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) * 0.0344;
  return distance;
  
}


void loop() {
// Check for button press to raise the arm
if (digitalRead(buttonPin) == HIGH && !moving) {
raiseArm();
  


// Check limit switches
if (digitalRead(limitUpPin) == LOW) {
armUp = true;
armDown = false;
digitalWrite(blueLEDPin, HIGH);
delay(1000);
digitalWrite(redLEDPin, LOW);
delay(1000);
}
else if (digitalRead(limitDownPin) == LOW) {
armDown = true;
armUp = false;
digitalWrite(blueLEDPin, LOW);
delay(500);
digitalWrite(redLEDPin, HIGH);
delay(500);
}
  
if(digitalRead(buttonPin) == LOW){
   digitalWrite(redLEDPin, HIGH);
   delay(1000);
}

if(digitalRead(buttonPin) == HIGH){
   digitalWrite(blueLEDPin, LOW);
   delay(1000);
}
  
void raiseArm() {
moving = true;

// Move arm up gradually
for (int pos = 0; pos <= 90; pos++) {
tollArm.write(pos);
delay(15);
if (digitalRead(limitUpPin) == LOW) break; // Stop if limit switch triggered
}

delay(3000); // Vehicle passes through

// Move arm down gradually
for (int pos = 90; pos >= 0; pos--) {
tollArm.write(pos);
flashRedLED();
delay(15);
if (digitalRead(limitDownPin) == LOW) break; // Stop if limit switch triggered
}
  

}
  




  
void flashRedLED() {
static unsigned long lastFlashTime = 0;
static bool ledState = false;
if (millis() - lastFlashTime > 200) {
ledState = !ledState;
digitalWrite(redLEDPin, ledState);
lastFlashTime = millis();
}
}
  


digitalWrite(redLEDPin, HIGH); // Keep red LED on after closed
moving = false;
  
}
  
}





 
Reasons:
  • RegEx Blacklisted phrase (1): I'm getting an error
  • Long answer (-1):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Aiden