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.

Last comments

Nicolas

NEW 3 weeks ago

Sorunome Sorunome

Thanks!

Sorunome

NEW 3 weeks ago

Nicolas Nicolas

To turn them off you simply set all to BLACK!

gb.lights.drawPixel(1, 1, BLACK);

Nicolas

3 weeks ago

Thanks!

Nicolas

NEW 3 weeks ago

Hi ! I want to know how can i turn off the led? I made this code to use LEDs :

if (gb.buttons.pressed(BUTTON_RIGHT)) {
    gb.lights.drawPixel(1, 1, WHITE);
  }

but i want to turn off the led when i press button B for exemple.

Thanks! 

Sorunome

3 weeks ago

To turn them off you simply set all to BLACK!

gb.lights.drawPixel(1, 1, BLACK);