Hier die Letztversion, die für mich funktioniert wie gewünscht. Besten Dank.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.setCursor(3,0);
myservo.write(0); // <------ put the servo at zero
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 37, 137); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
lcd.setCursor(1,0);
lcd.print("BALANCING MACHINE");
lcd.setCursor(0,1);
lcd.print(" by dynexhobby");
lcd.setCursor(0,2);
lcd.print("Modellbau - Technik");
lcd.setCursor(0,3);
lcd.print("Test Speed");
lcd.setCursor(19,3);
lcd.print("%");
lcd.setCursor(16,3);
lcd.print(" "); // This covers up the previous value
lcd.setCursor(16,3);
lcd.print(val-37);
delay(15); // waits for the servo to get there
}