This tutorial will attempt to make it easier to understand how to use the shiny RGB LEDs on the back of your Gamebuino META.

General Idea

The general idea is, that the lights are just a tiny image - one with 2x4 pixels! That means you can use all the tricks, animations etc. as explained in the Images tutorial on the lights, too! The image is gb.lights, it is an rgb565 image.

Pixel layout

gb.lights being two pixels wide and four pixels high means it directly maps onto the real-life LEDs of the Gamebuino! So, the upper-left pixel controls the upper-left LED, the lower-right pixel the lower-right LED etc.

That means, to turn the LED in the bottom-right red you can do:

gb.lights.drawPixel(1, 3, RED);

1 because x-coordinate one, that is on the right side of the image, thus the gamebuino.
3 because y-coordinate three, that is all on the bottom of the image, thus the gamebuino.
Keep in mind that x- and y coordinates start at zero!

Colors

The gb.lights image being RGB565 you can use any of the pre-defined colors or make your own!

All white will mean that the LEDs are, well, all white. And all black means they are completely turned off. So, to get e.g. a dimmer red on the LEDs, you have to draw a darker red to the image.

Fading example

This example will fade the LEDs from all white to all black.

#include <Gamebuino-Meta.h>

void setup() { gb.begin(); }

void fadeToBlack() { Color c; for (uint8_t level = 255; level > 0; level--) { while(!gb.update()); gb.lights.fill(gb.createColor(level, level, level)); } while(!gb.update()); gb.lights.fill(BLACK); }

void loop() { fadeToBlack(); }

Intensity

There is no need for your game ever to have an intensity setting to set the base intensity. This is already done automatically via the home menu.

Derniers commentaires

avatar
gamebuino-admin
il y a 6 mois
Author :  tikkel

... that was missing: Image img;

const byte led_spriteBuff[]={
 2,4,  //width, height
 8,0,  //8 frames animation
 1,    //frameloop on
 0xFF, //no transparent color
 1,    //indexed colors
 0xb0, 0x00, 0x00, 0x00,
 0x0b, 0x00, 0x00, 0x00,
 0x00, 0x0b, 0x00, 0x00,
 0x00, 0x00, 0x0b, 0x00,
 0x00, 0x00, 0x00, 0x0b,
 0x00, 0x00, 0x00, 0xb0,
 0x00, 0x00, 0xb0, 0x00,
 0x00, 0xb0, 0x00, 0x00,
};
Image led_sprite (led_spriteBuff);

void loop() {

gb.lights.drawImage(0, 0, led_sprite);

}

avatar
gamebuino-admin
il y a 6 mois
Author :  Steph

Yeah, it looks like it's not working... try this instead:

#include <Gamebuino-Meta.h>

const byte led_sprite_data[]={
2,4, // width, height
8,0, // 8 frames animation
0, // frameloop on
0xff, // no transparent color
1, // indexed colors

0xb0, 0x00, 0x00, 0x00,
0x0b, 0x00, 0x00, 0x00,
0x00, 0x0b, 0x00, 0x00,
0x00, 0x00, 0x0b, 0x00,
0x00, 0x00, 0x00, 0x0b,
0x00, 0x00, 0x00, 0xb0,
0x00, 0x00, 0xb0, 0x00,
0x00, 0xb0, 0x00, 0x00

};

void setup() {
gb.begin();
}

void loop() {
gb.waitForUpdate();

Image led(led_sprite_data);
uint16_t frames = led_sprite_data[2] | (led_sprite_data[3] &lt;&lt; 8);

led.setFrame(gb.frameCount % frames);
gb.lights.drawImage(0, 0, led);

}

avatar
gamebuino-admin
il y a 6 mois
Author :  tikkel

I would like to do a little LED animation. But only the LED on the top left lights up.

const byte led_sprite[]={
 2,4,  //width, height
 8,0,  //8 frames animation
 1,    //frameloop on
 0xFF, //no transparent color
 1,    //indexed colors
 0xb0, 0x00, 0x00, 0x00,
 0x0b, 0x00, 0x00, 0x00,
 0x00, 0x0b, 0x00, 0x00,
 0x00, 0x00, 0x0b, 0x00,
 0x00, 0x00, 0x00, 0x0b,
 0x00, 0x00, 0x00, 0xb0,
 0x00, 0x00, 0xb0, 0x00,
 0x00, 0xb0, 0x00, 0x00,
};
void loop() {
...
 gb.lights.drawImage(0, 0, led_sprite);
 ...
}