#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
//https://javl.github.io/image2cpp/
// '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
};
unsigned long dur_t, start_t;
int press_count;
long randheight;
int cntrect = 128;
int cntlower = 46;
bool game = true;
void setup() {
Serial.begin(9600);
// 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
}
display.clearDisplay();
pinMode(2, INPUT_PULLUP);
}
void loop() {
cntrect--;
//delay(10);
if(cntrect < 1){
cntrect = 128;
}
display.clearDisplay();
display.drawBitmap(0, 25, bitmap_DINO, LOGO_WIDTH, LOGO_HEIGHT, 1);
testfillrect();
testdrawline();
display.display();
//randheight = random(10,16);
if (digitalRead(2) == LOW){
//display.clearDisplay();
testdrawbitmap();
testdrawline();
testfillrect();
display.display();
}
}
unsigned long counting(int pin){
start_t = millis();
while(digitalRead(pin) == LOW){
//do nothing
}
return millis() - start_t;
}
void testdrawbitmap() {
display.clearDisplay();
display.drawBitmap(0, 10, bitmap_DINO, LOGO_WIDTH, LOGO_HEIGHT, 1);
//18, 20 indicates the start position of the picture.
testfillrect();
testdrawline();
display.display();
delay(1000);
display.clearDisplay();
display.drawBitmap(0, 25, bitmap_DINO, LOGO_WIDTH, LOGO_HEIGHT, 1);
//18, 20 indicates the start position of the picture.
testfillrect();
testdrawline();
display.display();
delay(1000);
}
void testdrawline() {
//display.clearDisplay(); // Clear display buffer
display.drawLine(0, 56, 127, 56, SSD1306_WHITE);
//0, 0 indicates the position of one end, 127, 63 indicates position of the other end.
// Update screen with each newly-drawn line
//delay(1000);
}
void testfillrect(void) {
//display.clearDisplay();
display.fillRect(cntrect, 46, 5, 10, SSD1306_INVERSE); //cntrect is 128
//10, 20 are for the position, 50 is the width of rect, 30 is the height of rect.
//delay(1000);
}