/*fw23
Servo über Poti mit LCD
*/
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
int Potiwert = 0;
int Winkel = 0;
Servo servo_6;
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// Init
lcd.init();
lcd.backlight();
servo_6.attach(6,544,2400);
pinMode(A0, INPUT);
Serial.begin(9600);
servo_6.write(0);
}
void loop() {
Potiwert = analogRead(A0);
Winkel = map(Potiwert, 0, 1023, 0, 180);
Serial.print("Potiwert = ");
Serial.println(Potiwert);
Serial.print("Winkel = ");
Serial.println(Winkel);
lcd.setCursor(0, 0);
lcd.print("Winkel: ");
lcd.print(Winkel);
lcd.print(" Grad ");
lcd.setCursor(0, 1);
lcd.print("Potiwert: ");
lcd.print(Potiwert);
servo_6.write(Winkel);
delay(100); // Wait for 100 millisecond(s)
}