Set RGB LED digitally for boot logo & flashlight

Instead of PWM, basic digital output is used to control the RGB LED in the
bootLogo() and flashlight() functions. This reduces code size for sketches
which don't use the setRGBled() function. In bootLogo(), instead of dimming
the red LED, the red then green then blue LEDs are lit in sequence at full
brightness.

digitalWriteRGB() was added as a public function and is also used for the
changes above.
This commit is contained in:
Scott Allen 2016-06-14 16:27:21 -04:00
parent e2458e6645
commit 3c4ebf59c2
3 changed files with 42 additions and 13 deletions

View File

@ -49,32 +49,32 @@ void Arduboy2Base::begin()
void Arduboy2Base::flashlight()
{
// sendLCDCommand(OLED_ALL_PIXELS_ON); // smaller than allPixelsOn()
setRGBled(255,255,255);
digitalWriteRGB(RGB_ON, RGB_ON, RGB_ON);
while(!pressed(DOWN_BUTTON)) {
idle();
}
setRGBled(0,0,0);
digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_OFF);
}
void Arduboy2Base::systemButtons() {
while (pressed(B_BUTTON)) {
digitalWrite(BLUE_LED, LOW); // turn on blue LED
digitalWrite(BLUE_LED, RGB_ON); // turn on blue LED
sysCtrlSound(UP_BUTTON + B_BUTTON, GREEN_LED, 0xff);
sysCtrlSound(DOWN_BUTTON + B_BUTTON, RED_LED, 0);
delay(200);
}
digitalWrite(BLUE_LED, HIGH); // turn off blue LED
digitalWrite(BLUE_LED, RGB_OFF); // turn off blue LED
}
void Arduboy2Base::sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal) {
if (pressed(buttons)) {
digitalWrite(BLUE_LED, HIGH); // turn off blue LED
digitalWrite(BLUE_LED, RGB_OFF); // turn off blue LED
delay(200);
digitalWrite(led, LOW); // turn on "acknowledge" LED
digitalWrite(led, RGB_ON); // turn on "acknowledge" LED
EEPROM.update(EEPROM_AUDIO_ON_OFF, eeVal);
delay(500);
digitalWrite(led, HIGH); // turn off "acknowledge" LED
digitalWrite(led, RGB_OFF); // turn off "acknowledge" LED
while (pressed(buttons)) {} // Wait for button release
}
@ -82,12 +82,18 @@ void Arduboy2Base::sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal) {
void Arduboy2Base::bootLogo()
{
// setRGBled(10,0,0);
for(int8_t y = -18; y<=24; y++) {
setRGBled(24-y, 0, 0);
digitalWrite(RED_LED, RGB_ON);
for(int8_t y = -18; y <= 24; y++) {
if (y == -4) {
digitalWriteRGB(RGB_OFF, RGB_ON, RGB_OFF); // green LED on
}
else if (y == 24) {
digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_ON); // blue LED on
}
clear();
drawBitmap(20,y, arduboy_logo, 88, 16, WHITE);
drawBitmap(20, y, arduboy_logo, 88, 16, WHITE);
display();
delay(27);
// longer delay post boot, we put it inside the loop to
@ -98,7 +104,7 @@ void Arduboy2Base::bootLogo()
}
delay(750);
setRGBled(0,0,0);
digitalWrite(BLUE_LED, RGB_OFF);
}
/* Frame management */

View File

@ -312,6 +312,17 @@ void ArduboyCore::setRGBled(uint8_t red, uint8_t green, uint8_t blue)
// only blue on devkit
digitalWrite(BLUE_LED, ~blue);
#endif
}
void ArduboyCore::digitalWriteRGB(uint8_t red, uint8_t green, uint8_t blue)
{
#ifdef ARDUBOY_10
digitalWrite(RED_LED, red);
digitalWrite(GREEN_LED, green);
digitalWrite(BLUE_LED, blue);
#elif defined(AB_DEVKIT)
digitalWrite(BLUE_LED, blue);
#endif
}
/* Buttons */

View File

@ -32,6 +32,8 @@
#define SAFE_MODE //< include safe mode (44 bytes)
#endif
#define RGB_ON LOW // for digitially setting an RGB LED on
#define RGB_OFF HIGH // for digitially setting an RGB LED off
#ifdef ARDUBOY_10
@ -254,9 +256,19 @@ public:
/// send a single byte command to the OLED
void static sendLCDCommand(uint8_t command);
/// set the light output of the RGB LEB
/// set the light output of the RGB LED
/**
* The brightness of each LED can be set to a value from
* 0 (fully off) to 255 (fully on).
*/
void static setRGBled(uint8_t red, uint8_t green, uint8_t blue);
/// set the RGB LEDs digitally, to either fully on or fully off
/**
* Use value RGB_ON or RGB_OFF for each color of LED.
*/
void static digitalWriteRGB(uint8_t red, uint8_t green, uint8_t blue);
/// boots the hardware
/**
* - sets input/output/pullup mode for pins