hi i have a code for a servo poss 1 0 poss 2 180 i need to add 2 leds to tell me what poss the servo is in i found the code online and it works for me im new to arduino if i post the code could any one help please
PLATE_FLIPPER.ino (1.38 KB)
hi i have a code for a servo poss 1 0 poss 2 180 i need to add 2 leds to tell me what poss the servo is in i found the code online and it works for me im new to arduino if i post the code could any one help please
PLATE_FLIPPER.ino (1.38 KB)
First, do you know how to wire a led? If no, search for tutorials on the web.
You need 2 leds and 2 resistors. Here is an example for one led:
Then you choose 2 pins to wire the leds, on this example the pin is the digital 13.
byte led1 = 13; // the pin the LED is connected to
byte led2 = 15; // the pin the LED is connected to
In your code, you need to declare these pins as OUTPUT
pinMode(led1, OUTPUT) // Declare the LED 1 as an output
pinMode(led2, OUTPUT) // Declare the LED 2 as an output
And you need to write instructions to light the leds depending on the servo position:
if( sw1){
Serial.println("sw1");
sw1 = false;
digitalWrite (led1,HIGH);
digitalWrite (led2,LOW);
myservo.write(0);
delay(0);
}
else if( sw2){
Serial.println("sw2");
sw2 = false;
digitalWrite (led2,HIGH);
digitalWrite (led1,LOW);
myservo.write(175);
delay(0);
}