I am trying to make a space invanders game but when I move the sprite accross the screen it flickers too much. Can anyone help?
Here is the code:
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1351.h>
// OLED Display Dimesions (pixels)
#define OLED_WIDTH 128
#define OLED_HEIGHT 128
// OLED Display PINS
#define DIN_PIN 12
#define CLK_PIN 11
#define CS_PIN 10
#define DC_PIN 9
#define RST_PIN 8
// On / Off Button Pin
#define OnOff_TOGGLE_SWITCH_PIN 4
// OLED Colours
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_SSD1351 display = Adafruit_SSD1351(OLED_WIDTH, OLED_HEIGHT, CS_PIN, DC_PIN, DIN_PIN, CLK_PIN, RST_PIN);
// OLED Graphics
static const unsigned char PROGMEM InvaderMiddleGfx [] =
{
B00100000,B10000000,
B00010001,B00000000,
B00111111,B10000000,
B01101110,B11000000,
B11111111,B11100000,
B10111111,B10100000,
B10100000,B10100000,
B00011011,B00000000
};
int XPos = 0;
void setup()
{
Serial.begin(9600);
Serial.println("Serial started on baud: 9600.");
display.begin();
display.fillScreen(BLACK);
}
void loop()
{
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("Space Invaders");
display.drawBitmap(XPos, 20, InvaderMiddleGfx, 11 , 8, WHITE);
display.fillRect(XPos, 20, 11, 8, BLACK);
XPos += 1;
if(XPos > 127)
XPos = 0;
}
I am using Arduino Uno and a 1.5" RGB OLED Module with the Adafruit_ssd1351 library.
Here is the OLED: 1.5inch Rgb Oled Screen Display Module Ssd1351 Driver 128x128 16-bit High Color Display Supports For Raspberry Pi /arduino/stm32 - Led Displays - AliExpress