Hi
So I'm extremely new to using Arduino and just coding in general, so for a project that i'm working on I want to be able to move a bitmap image for example in my test sketch a ball across an oled display pixel by pixel with two buttons one adjusting X axis and the other adjusting Y. I'm using an Arduino nano, a 128px by 64px oled display and the U8g library. I've poorly created a basic test code from all that I've learned in the past couple days for what i'd like, but not only is it very time consuming as i have to draw and convert a bitmap image for each position of the ball but it takes up a lot of the space in my Arduino so i was wondering is there a more efficient way or different way from what I've done to do this as I've dug around the internet and have yet to come up with anything. Any help or advice will be greatly appreciated
Here is my Test/sample code
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK);
const int buttonPinX = 5;
const int buttonPinY = 7;
int X = 0;
int Y = 1;
const uint8_t frame1[] PROGMEM = {
//Bitmap values would go here but can't due to word limit
const uint8_t frame2[] PROGMEM = {
//Bitmap values would go here
const uint8_t frame3[] PROGMEM = {
//Bitmap values would go here
const unsigned char PROGMEM frame4 [] = {
//Bitmap values would go here
const uint8_t frame5[] PROGMEM = {
//Bitmap values would go here
const uint8_t frame6[] PROGMEM = {
//Bitmap values would go here
int buttonState = LOW;
int buttonState1 = LOW;
void draw()
{
if(X == 0 && Y == 1 )
u8g.drawBitmapP( 0, 0, 16, 64, frame1); //Move ball Top Left
if (X == 1 && Y == 1 )
u8g.drawBitmapP( 0, 0, 16, 64, frame2); //Move ball Top Mid
if(X == 2 && Y == 1)
u8g.drawBitmapP( 0, 0, 16, 64, frame3); //Move ball Top Right
if(X == 0 && Y == 2 )
u8g.drawBitmapP( 0, 0, 16, 64, frame4); //Move ball Bottom Left
if(X == 1 && Y == 2 )
u8g.drawBitmapP( 0, 0, 16, 64, frame5); //Move ball Bottom Mid
if (X == 2 && Y == 2 )
u8g.drawBitmapP( 0, 0, 16, 64, frame6); //Move ball Bottom Right
}
void setup() {
pinMode(buttonPinX, INPUT);
pinMode(buttonPinY, INPUT);
}
void loop(void) {
buttonState = digitalRead(buttonPinX);
buttonState1 = digitalRead(buttonPinY);
u8g.firstPage();
do{
draw();
} while(u8g.nextPage());
if (buttonState == HIGH)
{ X ++;}
else if (buttonState1 == HIGH)
{ Y ++;}
if(X>2)
X = 0;
if(Y>2)
Y = 1;
delay(1000);
}