Created
June 14, 2020 12:35
-
-
Save sankarcheppali/53fb09663b190e7a149572e162e9955d to your computer and use it in GitHub Desktop.
blue pill based dino player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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