Skip to content

Instantly share code, notes, and snippets.

@sankarcheppali
Created June 14, 2020 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sankarcheppali/53fb09663b190e7a149572e162e9955d to your computer and use it in GitHub Desktop.
Save sankarcheppali/53fb09663b190e7a149572e162e9955d to your computer and use it in GitHub Desktop.
blue pill based dino player
#define KEYBOARD_ENABLE_CONTROL PB2
#define LDR_PIN PA4
#define LDR_OBSTACLE_THRESHOLD 980
#include "Keyboard.h"
void setup() {
Serial.begin(115200);
pinMode(LDR_PIN,INPUT);
pinMode(KEYBOARD_ENABLE_CONTROL,INPUT);
Keyboard.begin();
}
uint8_t isKeyBoardEnabled(){
return digitalRead(KEYBOARD_ENABLE_CONTROL);
}
uint8_t isObstaclePresent(){
uint32_t light = analogRead(LDR_PIN);
//Serial.print("Light :");
//Serial.println(light);
if(light > LDR_OBSTACLE_THRESHOLD){
return 1;
}
return 0;
}
void jump(){
if(isKeyBoardEnabled()){
Keyboard.write(' ');
}
}
void loop() {
uint8_t isObstacle = isObstaclePresent();
if(isObstacle){
jump();
Serial.println("jump!!");
delay(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment