So I'm trying to make a code that does this:
When a button is pushed:
move servo to 170, turn LED on and LED2 off
When a button is released:
move servo to 10, turn LED off and LED2 on
The servo works, but LED is on constantly and LED2 doesn't turn on at all
I know it's not the wiring because a simpler code turns the LED when the button is pushed (although the wiring for LED2 might be a little bit off, but I don't think so).
Here's the code:
#include <Servo.h>
Servo myservo;
const int BUTTON = 7;
const int LED = 13;
const int LED2 = 2;
int pos = 0;
int val = 0;
Wow! Thanks so much! It was that missing 2 that broke things, and now everything is working! The (pos = 170) and (pos = 10) were working, but I like the simplicity of your version better. Thanks again!
And lastly, the little servo problem I posted at the end. When it gets to 170, it starts twitching and making clicking noises. It's as if it's trying to go farther but it can't. Know how I can solve this? Thanks in advance!