#include <SPI.h> //for IIC -Inter intergrated circuit
#include <Wire.h>
#include <Adafruit_GFX.h> // for graphic
#include <Adafruit_SSD1306.h> //for oled screen
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// no need to change, always as default
#define LOGO_HEIGHT 32
#define LOGO_WIDTH 32
// 'DINO', 32x32px
const unsigned char bitmap_DINO [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0xef, 0xfc, 0x00, 0x00, 0xef, 0xfc, 0x00, 0x00, 0xff, 0xfc,
0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0xfe, 0x00,
0x00, 0x00, 0xff, 0xe0, 0x0c, 0x00, 0xff, 0xe0, 0x0c, 0x01, 0xfc, 0x00, 0x0c, 0x07, 0xfc, 0x00,
0x0e, 0x1f, 0xff, 0x00, 0x0f, 0x1f, 0xff, 0x00, 0x0f, 0xff, 0xff, 0x00, 0x0f, 0xff, 0xfc, 0x00,
0x0f, 0xff, 0xfc, 0x00, 0x0f, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xf0, 0x00, 0x03, 0xff, 0xf0, 0x00,
0x00, 0x7f, 0xe0, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x7d, 0xc0, 0x00, 0x00, 0x78, 0xc0, 0x00,
0x00, 0x78, 0xc0, 0x00, 0x00, 0x60, 0xc0, 0x00, 0x00, 0x78, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00
};
int pos_x = 127;
bool game = true;
unsigned long dur_t, start_t;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(3, INPUT_PULLUP);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3c, safety precheck
Serial.println(F("SSD1306 allocation failed"));
while(true){} // Don't proceed, loop forever
}
}
void loop() {
// put your main code here, to run repeatedly:
while(game == true){
display.clearDisplay();
pos_x--;
if(pos_x < 1){pos_x = 127;}
testfillrect(pos_x);
if(digitalRead(3)==LOW){
testdrawbitmap(0);
}
else if(digitalRead(3) != LOW){
testdrawbitmap(32);
}
display.display();
}
}
void testdrawbitmap(int dino_height) {
display.drawBitmap(0, dino_height, bitmap_DINO, LOGO_WIDTH, LOGO_HEIGHT, 1);
}
void testfillrect(int x) {
display.fillRect(x, 52, 5, 12, SSD1306_INVERSE);
}
void showWord(){
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(40, 25);
display.print("GAME OVER");
}
unsigned long counting(int pin){
start_t = millis();
while(digitalRead(pin) == LOW){
//do nothing
}
return millis() - start_t;
}