#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int Y_pin = A0; // analog pin connected to Y output
const int X_pin = A1;
Servo myservo;
int val;
void setup() {
myservo.attach(9);
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("Hello Everyone");
lcd.setCursor(1, 1);
lcd.print(" Aadarsh");
}
void loop() {
val = analogRead(Y_pin);
val = map(val, 0, 511, 0, 90);
val = analogRead(X_pin);
val = map(val, 512, 1023, 91, 180);
myservo.write(val);
delay(15);
if (val >= 0 && val <= 90)
{
Serial.println("Correct Answer!!");
lcd.clear();
lcd.print("Correct Answer!");
}
else if (val >= 100 && val <= 180)
{
Serial.println("Wrong Answer...");
lcd.clear();
lcd.print("Wrong Answer...");
}
else
{
Serial.println("Move for your Answer!");
lcd.clear();
lcd.print("Move for your");
lcd.setCursor(1,1);
lcd.print("Answer");
}
}
Comments
Please log in or sign up to comment.