It contains a LDR as the sensor to detect the obstacles coming in the way in the game , the LDR value sends the signal to the servo motor to rotate 90° to press the space-bar button of the keyboard to make the Dino jump !
It contains a LDR as the sensor to detect the obstacles coming in the way in the game , the LDR value sends the signal to the servo motor to rotate 90° to press the space-bar button of the keyboard to make the Dino jump !
Code !
#include<liquidCrystal_I2C.h> #include<Wire.h> #include<Servo.h> LiquidCrystal_I2C lcd(0x27,16,2); Servo myservo; int pos; const int ldrPin = A0; void setup() { // Serial.begin(9600); lcd.init(); lcd.backlight(); lcd.blink(); pinMode(ldrPin, INPUT); myservo.attach(9); lcd.setCursor(0,0); lcd.print(" IWBEAG"); delay(1000); lcd.clear(); } void loop() { int ldrStatus = analogRead(ldrPin); // Serial.println(ldrStatus); myservo.write(0); lcd.setCursor(0,0); lcd.print("Ldr value "); lcd.print(ldrStatus); //lcd.print("#"); delay(50); lcd.clear(); if(ldrStatus<=400){ myservo.write(90); delay(150); myservo.write(0); delay(200); } }