Ok, then let's skip the questions regarding position and speed.
I have been tweaking the combined sketches I have put together and am almost satisfied with the outcome except for one thing, which I am unsure how to deal with and that is when 'angle' is between around 94 to 113, led pins 13,12,11,10 are all lit and should be off.
I think it has something to do with one of the for loops - either in setup or the one at the beginning of the loop, but can't figure out what to do to fix it, so any help here would be appreciated. Anything else will not be necessary. Thank you.
Following is my latest version of this sketch as referenced above:
#include <Servo.h>
// these constants won't change:
const int analogPin = A0; // the pin that the potentiometer is attached
const int ledCount = 9; // to the number of LEDs in the bar graph
const int servoPin = 3;
Servo servo;int ledPins[] = {
13,12,11,10,9,8,7,6,5 }; // an array of pin numbers
//to which LEDs are attachedvoid setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
servo.attach(servoPin);
}
}void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
int angle = sensorReading / 6;
Serial.println(angle); // print out the value you read
delay(1); // delay in between reads for stability
servo.write(angle);if (angle >=95){
// loop over the LED array:
for (int thisLed = 0; thisLed <= ledCount; thisLed++) {
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
else if (angle <=85){
// loop over the LED array:
for (int thisLed = 4; thisLed > -5; thisLed--) {
// turn the pin for this element on:
if (thisLed > ledLevel-1) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
}