I am trying to get a LED to brighten and dim when I turn the pot, also at the same time while turning the pot I am trying to drive a servo.
I have one script that will do the Brighten then Dim of the LED whilst turning the pot. And I have another script that will turn the servo 180 when I turn the pot.
Now I am trying to combine these two scripts to do both at the same time.
I am having problems. Could someone please check my code or direct me to better code that will do what I want.
Problems I am having: The LED does not fad up and down, it only goes on.
The Servo appears to be stuttering more than when it is driven just by the pot servo script.
#include <Servo.h>
const int analogInPin = A5; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
Servo myservo;
int sensorValue = 0; // value read from the pot
int OutputValue = 0; // value output to the PWM (analog out)
int ServoOutputValue = 0; //value output to the Servo
int ServoValue = 0; //variable to read the value from the analog pin
void setup() {
myservo.attach(11);
}
void loop() {
//This is where I control the LED with the pot
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
OutputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, OutputValue);
//This is where I drive the servo
// assign the analogInPin to the ServoValue
ServoValue = analogRead(analogInPin);
//reassign the ServoValue
ServoOutputValue = map(ServoValue, 0, 1023, 0, 180);
myservo.write(ServoOutputValue);
delay(10);
}