Libraries, utilities, bootloaders...
by Georgian » Mon Sep 05, 2016 9:04 pm
Hello fellow gamebuino fans. I have wrote a very simple and basic paint software (maybe etch-a-sketch?) for gamebuino. All it dose is draw one pixel at the coords x, y. By pressing the arraw keys you move the pixel on the screen. The button B clears the screen.
Is there any way to gat a print screen and save it to SD? It would be nice to be able to do this.
If you draw something cool please post it here
Thanks for taking your time to read this
![Smile :)](./images/smilies/icon_e_smile.gif)
Georgian.
- Code: Select all
#include <Gamebuino.h>
#include <SPI.h>
Gamebuino gb;
byte x = 0;
byte y = 0;
void setup() {
gb.begin();
gb.titleScreen(F("Paint DEMO"));
gb.display.persistence = true;
gb.display.clear();
} //setup END
void loop() {
if (gb.update()) {
if (gb.buttons.pressed(BTN_C)) {
gb.titleScreen(F("Paint DEMO"));
} // if (gb.buttons.pressed(BTN_C)) END
if (gb.buttons.pressed(BTN_DOWN)) {
y += 1;
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_UP)) {
y -= 1;
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_LEFT)) {
x -= 1;
//gb.display.drawFastVLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_RIGHT)) {
x += 1;
//gb.display.drawFastVLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_B)) {
gb.display.clear();
}
gb.display.drawPixel(x, y);
} //if (gb.update()) END
} //loop END
- Attachments
-
PAINT.zip
- (12.49 KiB) Downloaded 953 times
-
Georgian
-
- Posts: 22
- Joined: Sat Aug 27, 2016 4:56 pm
by mobbarley » Thu Sep 29, 2016 3:52 pm
Hi,
Which file format do you want it to be? I know a bit about bitmap encoding in C so can give it a try. However I still don't have my gamebuino delivered yet so cant test the SD card save part as the simulator does not yet have the SD card functionality.
Regards,
Mobby
-
![User avatar](./download/file.php?avatar=1874_1475164590.jpg)
mobbarley
-
- Posts: 4
- Joined: Thu Sep 29, 2016 3:41 pm
by Georgian » Thu Sep 29, 2016 10:28 pm
Hi and thank you for your replay.
Any file format should pe ok. BMP is the best i think. I don't have much time but i'll update this pice of software, just for fun. For the next version I want to send the coordinates via UART and have them printed on the screen. I'm not an expert but maybe someone will find something usefull in this code.
-
Georgian
-
- Posts: 22
- Joined: Sat Aug 27, 2016 4:56 pm
by mobbarley » Fri Sep 30, 2016 3:05 pm
-
![User avatar](./download/file.php?avatar=1874_1475164590.jpg)
mobbarley
-
- Posts: 4
- Joined: Thu Sep 29, 2016 3:41 pm
by mobbarley » Fri Sep 30, 2016 3:32 pm
I did some mod to your code now the pen switches up and down when you press the button A, button B is for clear screen. I guess now you can use it for a context menu or something.
Only when the pen is down the pixels will be drawn.
- Code: Select all
#include <Gamebuino.h>
#include <SPI.h>
Gamebuino gb;
boolean penDown = false;
byte x = 0;
byte y = 0;
void setup() {
gb.begin();
gb.titleScreen(F("Paint DEMO"));
gb.display.persistence = true;
gb.display.clear();
} //setup END
void loop() {
if (gb.update()) {
if (gb.buttons.pressed(BTN_C)) {
gb.titleScreen(F("Paint DEMO"));
} // if (gb.buttons.pressed(BTN_C)) END
if (gb.buttons.pressed(BTN_DOWN)) {
y += 1;
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_UP)) {
y -= 1;
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_LEFT)) {
x -= 1;
//gb.display.drawFastVLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_RIGHT)) {
x += 1;
//gb.display.drawFastVLine(x, y, 1);
}
// Use button A to switch between pen up & down modes
if (gb.buttons.pressed(BTN_A)) {
penDown = !penDown;
}
// If pen is down then pressing button B pulls it up
if (gb.buttons.pressed(BTN_B)) {
gb.display.clear();
}
if (penDown) {
gb.display.drawPixel(x, y);
}
} //if (gb.update()) END
} //loop END
Hex file is below:
-
![User avatar](./download/file.php?avatar=1874_1475164590.jpg)
mobbarley
-
- Posts: 4
- Joined: Thu Sep 29, 2016 3:41 pm
by naed » Sat Oct 01, 2016 10:39 pm
Hello,
That's a very nice program you've written there, looking forward to see if you manage to implement a save feature
I'd like to report a bug that I've found with the original code, if I exit to the title screen and then re-enter the paint program I am no longer able to draw anything, I can move the cursor around but it will not draw anything at all.
Keep up the great work
-
![User avatar](./download/file.php?avatar=1789_1469487866.jpg)
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by Georgian » Sun Oct 02, 2016 7:51 pm
Hello Naed,
I see the bug now and it's quite tricky as the gb.titleScreen() sets the gb.display.resistence to false. Thats why the display clears on every frame change. Here is a quick and dirty fix. After you pres C and start again you will have to press B to clear the display. I make it impossible to move the "brush" outside the screen area. Thank you for sharing your experience.
- Code: Select all
#include <Gamebuino.h>
#include <SPI.h>
Gamebuino gb;
byte x = 0;
byte y = 0;
//char coords[7] = "84,48";
boolean penDown = false;
void setup() {
gb.begin();
gb.titleScreen(F("Paint DEMO"));
gb.display.persistence = true;
gb.display.clear();
//gb.setFrameRate(10);
} //setup END
void loop() {
//gb.display.clear();
gb.display.persistence = true;
if (gb.update()) {
if (gb.buttons.pressed(BTN_C)) {
x = 0;
y = 0;
gb.titleScreen(F("Paint DEMO"));
} // if (gb.buttons.pressed(BTN_C)) END
if (gb.buttons.pressed(BTN_DOWN)) {
y += 1;
if (y == 48) {
y = 47;
}
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_UP)) {
y -= 1;
if (y == 255) {
y = 0;
}
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_LEFT)) {
x -= 1;
if (x == 255) {
x = 0;
}
//gb.display.drawFastVLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_RIGHT)) {
x += 1;
if (x == 84) {
x = 83;
}
//gb.display.drawFastVLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_B)) {
gb.display.clear();
x = 0;
y = 0;
}
// Use button A to switch between pen up & down modes
if (gb.buttons.pressed(BTN_A)) {
penDown = !penDown;
}
// If pen is down then pressing button B pulls it up
if (gb.buttons.pressed(BTN_B)) {
gb.display.clear();
}
if (penDown) {
gb.display.drawPixel(x, y);
}
//gb.display.drawPixel(x, y);
} //if (gb.update()) END
} //loop END
- Attachments
-
PAINT.zip
- (12.5 KiB) Downloaded 907 times
-
Georgian
-
- Posts: 22
- Joined: Sat Aug 27, 2016 4:56 pm
by Georgian » Sun Oct 02, 2016 8:43 pm
I fixed it now. I still try to figure it out if the pen is up, then draw just one pixel on the screen and clear the one behind. gb.display.clearPixel(x - 1, y - 1) would pe perfect here but it's not implemented in the library.
- Code: Select all
#include <Gamebuino.h>
#include <SPI.h>
Gamebuino gb;
byte x = 0;
byte y = 0;
//char coords[7] = "84,48";
boolean penDown = true;
const byte drawPixelHere[] PROGMEM = {
8,3,
0x40,
0xA0,
0x40,
};
const byte emptyPixel[] PROGMEM = {
8,3,
0x0,
0x0,
0x0,
};
void setup() {
gb.begin();
gb.titleScreen(F("Paint DEMO"));
gb.display.persistence = true;
gb.display.clear();
//gb.setFrameRate(10);
} //setup END
void loop() {
if (gb.update()) {
// If pen is down then pressing button C pulls it up
if (gb.buttons.pressed(BTN_C)) {
x = 0;
y = 0;
gb.titleScreen(F("Paint DEMO"));
gb.display.clear();
gb.display.persistence = true;
} // if (gb.buttons.pressed(BTN_C)) END
if (gb.buttons.pressed(BTN_DOWN)) {
y += 1;
if (y == 48) {
y = 47;
}
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_UP)) {
y -= 1;
if (y == 255) {
y = 0;
}
//gb.display.drawFastHLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_LEFT)) {
x -= 1;
if (x == 255) {
x = 0;
}
//gb.display.drawFastVLine(x, y, 1);
}
if (gb.buttons.pressed(BTN_RIGHT)) {
x += 1;
if (x == 84) {
x = 83;
}
//gb.display.drawFastVLine(x, y, 1);
}
// Use button A to switch between pen up & down modes
if (gb.buttons.pressed(BTN_A)) {
penDown = !penDown;
}
// If pen is down then pressing button B pulls it up
if (gb.buttons.pressed(BTN_B)) {
x = 0;
y = 0;
gb.display.clear();
}
if (penDown) {
gb.display.drawPixel(x, y);
} else {
//gb.display.drawBitmap(x - 1, y - 1, drawPixelHere);
}
//gb.display.drawPixel(x, y);
} //if (gb.update()) END
} //loop END
-
Georgian
-
- Posts: 22
- Joined: Sat Aug 27, 2016 4:56 pm
by wuuff » Tue Oct 11, 2016 6:13 am
If you're still trying to save the screen, you can access the screen buffer directly:
http://gamebuino.com/wiki/index.php?tit ... .getBufferI think the best approach for this is probably to output a bare-bones bitmap image (only output bitmaps with a 2-color palette). For that you would need to look at the format of bmp files, and then look at some projects that write to the SD card. It should be simple enough to convert the raw bytes of the screen buffer to the format required for the bitmap using a small buffer and appending to the file on the SD card. I haven't looked at the libraries for writing to SD though.
This could actually be made into a standalone library that anybody could drop into their games, allowing any application to save screenshots by calling a single function. Since it would require an SD card library, large games probably wouldn't have space to add it though. Still, it seems like a cool idea! I would want to try making it myself if I had time.
This could also be made to work in the reverse direction and load bitmaps from the SD card too, although I doubt it could handle arbitrary bitmaps. It perhaps would only be able to load ones that it generated since the code needs to stay small.
-
wuuff
-
- Posts: 61
- Joined: Sun Aug 28, 2016 6:05 am
Return to Software Development
Who is online
Users browsing this forum: No registered users and 8 guests