dauntless75
Published © GPL3+

Dinosaur game played with arduino

This simple system detects incoming obstacles and jumps over them during both the day and night phases of the google chrome dinosaur game.

BeginnerShowcase (no instructions)23
Dinosaur game played with arduino

Things used in this project

Hardware components

Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Arduino Nano R3
Arduino Nano R3
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Photo resistor
Photo resistor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Switch Actuator, APEM A01 series Illuminated Push-Button Switches
Switch Actuator, APEM A01 series Illuminated Push-Button Switches
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Tape, Clear
Tape, Clear

Story

Read more

Schematics

Schematics

Code

The Code:

Arduino
// Servo - Version: Latest 
#include <Servo.h>

#define pressed LOW
#define margin 5
#define wait 100
//macros

const byte sensorPinup = A7;
const byte Button = 2;
//detection

const byte servoPin = 5;
Servo myservo;
//servo

unsigned int baseLine; 
boolean calibrated = false; //avoid premature activaions qol
int switchState = 1; //open (pullup resistor);

void setup() {
  Serial.begin(9600); // start serial port
  while(!Serial) { //wait 
    ; }
  pinMode(Button, INPUT); //calibration button
  myservo.attach(servoPin);
  myservo.write(100);
  //servo position 
}

void loop() {
  switchState = digitalRead(Button);
  Calibration(switchState);
  //for baseline
  
  if(calibrated == true) {
    
    myservo.write(100); // reset servo pos
    if(abs(analogRead(sensorPinup) - baseLine) > margin) { // measure difference in values
      myservo.write(75); //press spacebar
    }
  delay(wait);// give servo time to move
  }
}
bool Calibration(int switchState) {
  if(switchState == pressed) {
    baseLine = analogRead(sensorPinup);
    Serial.println("Calibrated!");
    Serial.print(baseLine); // print values
    calibrated = true; // begin cactus detection
  }
} 

Credits

dauntless75
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.