#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 cirX=10;
int cirY=31;
int rectX=100;
int rectY=0;
int w =25;
int high =63;
int r =10;
int score=0;
void loop() {
Serial.println(score);
draw();
scores();
move();
screen.setCursor(1,55);
screen.setTextSize(1);
screen.setTextColor(1);
screen.print("Score is:");
screen.print(score);
screen.display();
}
//draws rect and cir
void draw(){
//screen.clearDisplay();
screen.fillCircle(cirX,cirY,r,1);
screen.drawRect(rectX,rectY, w, high,1);
screen.display();
}
void scores(){
if(cirX>=90 && cirX<=135){
score++;
cirX=10;
screen.clearDisplay();
delay(1000);
}
}
void move(){
while(digitalRead(l_button)==1){
cirX++;
Serial.println(cirX);
delay(10);
screen.clearDisplay();
if(cirX>137){
cirX=1;
}
}
}