Servo & Led control

hello guys i need your help
There are 4 LEDs in a system and one servo.
The servo has 4 positions, these are 0 60 120 180 degrees. I wait for 5 seconds in every movement of the servo and the leds are on to tell what degree it is, example 1.led indicates 0 degrees, 2. led 60 degrees. I am running the servo motor, but I cannot add the leds, can you help? Thank you from now.

#include <Servo.h>
Our servo motor;
// we defined a servo motor named our motor

int led1 = 2; // We assigned the led pins
int led2 = 3;
int led3 = 4;
int led4 = 5;

void setup() {
our engine.attach(A0);
}

void loop()
{

our engine.write(0); // get to 0 degrees
delay(5000); // wait 5 seconds

our engine.write(60);// come to 60 degrees
delay(5000);// wait 5 seconds

our engine.write(120);// come to 120 degrees
delay(5000);// wait 5 seconds

our engine.write(180);// come to 180 degrees
}

We can't see your code
Use code tags.

Hi, I'm so sorry, I edited.

That code will not compile. Look at the examples in the Servo library to see how to use it.

Make the LED pins OUTPUTS with pinMode.

When you write to the servo, digitalWrite HIGH to the LED pin that you want to turn on for that angle.

"our engine" is not a valid name because it has a space in it. The closest you can get to a space that is valid in a name is '_'.

Our servo motor;
That does not work. You probably wanted:
'Servo our_engine;'

You forgot to set your LED pins to pinMode(pin, OUTPUT);. Do that in setup() for each output pin.

You would typically use digitalWrite(pin, HIGH); to turn an LED on and digitalWrite(pin, LOW); to turn an LED off.

thank you, the engine name was wrong because I did the translation, I fixed it, thank you for your help

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.