Arduino sets the servo position via a pot. The LED lights when the servo function moves the servo to a new position.
When I physically twist the servo, the LED comes on and I don't know why?
My loop just calls these two functions. The first reads a pot pin 5 times and maps an average to degrees. The second moves the servo.
void pot3(){
pot = 0;
for (int i=1; i <= 5; i++){
pot = pot + analogRead(potpin);
}
pot = map(pot/5, 0, 1023, 0, 180);
}
void servo1x(int pos, int dlyx) {
if (pos < pos1)
{
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
for(int i = pos1; i >= pos && i >= servo1start; i--) // goes from degrees to degrees
{
servo1.write(i); // tell servo to go to position in variable 'pos'
delay(dlyx); // waits ms for the servo to reach the position
pos1 = i;
}
digitalWrite(13, LOW); // turn the LED off (LOW is the voltage level)
}
else if (pos > pos1) {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
for(int i = pos1; i <= pos && i <= servo1stop; i++) // goes from degrees to degrees
{ // in steps of 1 degree
servo1.write(i); // tell servo to go to position in variable 'pos'
delay(dlyx); // waits ms for the servo to reach the position
pos1 = i;
}
digitalWrite(13, LOW); // turn the LED off (LOW is the voltage level)
}
}
Just because I apply pressure to the servo there is no way Arduino can know about it, so why does LED come on? It is very consistent with pressure too. It goes from a flicker to strong brightness with more pressure.
Also, at the endpoints of my pot, the servo is not stable and twitches constantly.
Finally, I have an LCD function that will print the current angle. If I include a call to that function, none of the above happens and the servo takes consistent coarse steps to any new position.
it's more complex than it needs to be and works fine, but maybe takes a bit of time...?
void lcd2(){
// picture loop
u8g.firstPage();
do {
draw2();
}
while( u8g.nextPage() );
xPos = xPos + 14;
if (xPos >= 128) xPos = 0;
if (++yPos >= 76) yPos = 0;
}
void draw2() {
//graphic commands to redraw the complete screen should be placed here
//u8g.setFontPosTop();
//u8g.setFont(u8g_font_unifontr);
u8g.setFont(u8g_font_fub11); //fub11, 14, 17, 20, 25
u8g.setPrintPos(0, 12);
u8g.print(pot);
u8g.print("deg ");
u8g.drawStr(xPos, 62, "."); //scrolling marq2uee
}