The photoresistor detect the light from obstacle which are trees in the game and send to arduino a value different then before, if this value is equal or greater than a defined value in arduino then the servo motor rotates 90 degree and presses the space button on the keyboard for 250 milliseconds, after this the dino jump the obstacle.
this is the code below:
#include <Servo.h>
int pot=A0;
int val;
Servo myservo;
void setup() {
Serial.begin(9600);
myservo.attach(9);
}
void loop() {
myservo.write(90);
val=analogRead(pot);
Serial.println(val);
if(val>=730){
myservo.write(0);
delay(250);
myservo.write(90);
}
}
here is a video to show how it works.
Aucun commentaire:
Enregistrer un commentaire