#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=31;
int r=10;
int white=1;
int rectX=100;
int rectY=0;
int width=25;
int height=63;
int score = 0;
void loop() {
Serial.println(score);
draw();
checkScore();
movePuck();
screen.setCursor(1,56);//puts cursor in lower left
screen.setTextSize(1);
screen.setTextColor(white);
screen.print("score: ");
screen.print(score);
screen.display();
}
//this function draws a rectangle and a circle and displays
void draw(){
screen.fillCircle(circX,circY,r,white);
screen.drawRect(rectX,rectY,width,height,white);
screen.display();
}
//checks to see if circ x position is within range
//of touching square, if it is, add ot the score
void checkScore(){
if(circX>=90 && circX<=135){
score++;
circX=10;
screen.clearDisplay();
delay(1000);
}
}
//while button is pressed, circ x position increases to move
//the puck. Also checks to make sure the circ x position
//doesn't get too high and go off screen
void movePuck(){
while(digitalRead(l_button)==1){
circX++;//also can do circX = circX +1;
delay(10);
screen.clearDisplay();
if(circX>137){
circX=1;
}
}
}