Help!! program will not run and no error given

Hi all I am completely lost now :’( and need some help please. This program should light up 4 LED’s as the pot is moved from 0 to 1023, at the same time the servo arm should move too. I need this for a little crane project I am working on. I do not understand what I am doing wrong, and can’t see why it will not compile.

Any help would be most appreciated.

Kind Regards

Mr C

/* LED WARNING LIGHT FOR MAXIMUM MOVEMENT ON SERVO
*/
#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
int value = LOW; // previous value of the LED
int oppvalue = HIGH; // opposite value
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
int potPin = 2; // analog pin the pot is on
int potVal; // initial analog value


void setup()
{
pinMode(ledPin1, OUTPUT); // sets the digital pin as output
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
}

void loop()
{
// here is where you'd put code that needs to be running all the time.

// Start by turning off all the LEDs

digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);

potVal = analogRead(potPin); // read the value from the sensor
// this should be btw 0 and 1023

{ 
  potval = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  potval = map(potval, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(potval);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
} 


if (potVal > 0) {
digitalWrite(ledPin4, HIGH);
}
if (potVal > 355) {
digitalWrite(ledPin1, HIGH);
}
if (potVal > 712) {
digitalWrite(ledPin2, HIGH);
}
if (potVal > 976) {
digitalWrite(ledPin3, HIGH);
}
}
{
  potval = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  potval = map(potval, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(potval);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

What's with the open and close braces around this section? Did you intend to have some conditional before it?

Thnx for the reply, but as usual I figured it out after I posted.

This is the correct code is anyone is interested (works a treat) now to get the other servos hocked up… all i needed was to talk it out load :slight_smile:

thnx again all

/* ARM LED INDICATOR FOR MOTION LEFT
*/
#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
int value = LOW; // previous value of the LED
int oppvalue = HIGH; // opposite value
long previousMillis = 0; // will store last time LED was updated
long interval = 1000; // interval at which to blink (milliseconds)
int potPin = 2; // analog pin the pot is on
int potVal = 0; // initial analog value
int val;    // variable to read the value from the analog pin 

void setup()
{
pinMode(ledPin1, OUTPUT); // sets the digital pin as output
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
}

void loop()
{
{ 
  
  val = analogRead(potPin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
} 

  
  // here is where you'd put code that needs to be running all the time.

// Start by turning off all the LEDs

digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);

potVal = analogRead(potPin); // read the value from the sensor
// this should be btw 0 and 1023


if (potVal > 0) {
digitalWrite(ledPin4, HIGH);
}
if (potVal > 355) {
digitalWrite(ledPin1, HIGH);
}
if (potVal > 712) {
digitalWrite(ledPin2, HIGH);
}
if (potVal > 976) {
digitalWrite(ledPin3, HIGH);
}
}