Lights

Créations

Sorunome

il y a 5 ans

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.

Voir la création

clement

NEW il y a 5 ans

just typo error on ligts => lights


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


seems to be corrected befor my comment :) 


Sorunome

il y a 5 ans

fixed, thanks

Sorunome

NEW il y a 5 ans

clement clement

fixed, thanks

ragnarok93

NEW il y a 5 ans

Wooow, thanks Sorunome for tutorial ;). You are the best :D. Thanks to your effort many people will understand how to code new things to their games ;).

UnPolacoLoco

NEW il y a 5 ans

I'd add a link to this in the Graphics Reference :)

Nicolas

NEW il y a 5 ans

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

il y a 5 ans

To turn them off you simply set all to BLACK!

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

Sorunome

NEW il y a 5 ans

Nicolas Nicolas

To turn them off you simply set all to BLACK!

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

Nicolas

il y a 5 ans

Thanks!

Nicolas

NEW il y a 5 ans

Sorunome Sorunome

Thanks!

iPad

NEW il y a 5 ans

Message supprimé

tikkel

NEW il y a 4 ans

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);
 ...
}



Steph

il y a 4 ans

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] << 8);

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

tikkel

il y a 4 ans

... 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);
 ...
}

Steph

NEW il y a 4 ans

tikkel tikkel

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] << 8);

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

tikkel

NEW il y a 4 ans

tikkel 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);
 ...
}