#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 = 128;
int screen_height = 64;
//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);
// put your setup code here, to run once:
screen.begin(SSD1306_SWITCHCAPVCC,address);
screen.clearDisplay();//clears everything off display
Serial.begin(9600);
}
int circX = 10;
int circY = 32;
int r = 10;
int rectX = 70;
int rectY = 0;
int rectW = 30;
int rectH = 64;
int score=0;
void loop() {
draw();
move();
checkscore();
printscore();
}
void draw(){
screen.fillCircle(circX, circY,r,1);
screen.drawRect(rectX, rectY,rectW, rectH,1);
screen.display();
}
void move(){
while(digitalRead(l_button)==1){
circX=circX+1;
if(circX>137){
circX=10;
}
//Serial.println(circX);
screen.clearDisplay();
}
}
void checkscore(){
if(circX>80 && circX<84){
score=score+1;
circX=10;
screen.clearDisplay();
delay(1000);
}
Serial.println(score);
}
void printscore(){
screen.setCursor(0,0);
screen.setTextColor(1);
screen.setTextSize(1);
screen.print("score:");
screen.print(score);
screen.display();
}