#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
int address = 60; //0x3C; //means 12 (C) plus 3 16s or 48
//12 + 48 is 60.
int r_button = 2;
int l_button = 3;
int screen_width = 127;
int screen_height = 64;
int circ_x=0;
int start_time=0;
//declaring my new lcd and naming it "screen
Adafruit_SSD1306 screen(screen_width,screen_height,&Wire, -1);
//(pixels wide, pixels tall, wire library, -1 is for the uno board reset pin)
void setup() {
pinMode(r_button,INPUT);
pinMode(l_button,INPUT);
randomSeed(analogRead(0));
// put your setup code here, to run once:
screen.begin(SSD1306_SWITCHCAPVCC,address);
screen.clearDisplay();//clears everything off display
}
int x=0;
int score=0;
void loop() {
long start_time=millis();
while((millis()-start_time)<1000){
if(x==circ_x){
score++;
circ_x=random(0,127);
}
if(digitalRead(3)==1){
x--;
}
if (digitalRead(2)==1){
x++;
}
drawcircandrect();
}
circ_x=random(0,127);
}
void drawcircandrect(){
screen.drawRect(x,30,20,20,1);
screen.fillCircle(circ_x,30,10,1);
printscore();
printcords();
screen.display();
delay(10);
screen.clearDisplay();
}
void printscore(){
screen.setCursor(0,0);
screen.setTextSize(1);
screen.setTextColor(1);
screen.print("Score: ");
screen.print(score);
}
void printcords(){
screen.setCursor(90,0);
screen.setTextSize(1);
screen.setTextColor(1);
screen.print(x);
screen.print(" ");
screen.print(screen_height/2);
screen.setCursor(90,10);
screen.print(millis()/1000);
}