Red / Blue LED won't analog if arduboy.begin();

(Bryn) #1

I have a more complicated function than this that can adjust the RGB values with the buttons to test but this explains the issue simply enough:

If I do something like this
void setup() {
Then the LED has the Red and Blue at full blast, but the green is just baaaarely on as you’d expect.

If I do something like this
void setup() {
then it works perfectly as you’d expect. All LEDs are just barely lit.Only difference is the lack of “begin” so the screen does not turn on and my scripts don’t run so I can’t actually do the things I’d want to with the LED.
I tested this with the manual analogWrite() too and it was the same behavior.
I’m assuming there is something in the library that’s maybe making this digital instead of analogue or disabling the PWM on the port but I don’t really know about this stuff and I’m not an expert at all. This is my first arduino thing and I’ve only ever done javascript for web based games and actual websites.

(Scott) #2

There is a conflict with timer use in the Arduboy library between the RGB LED and the sound code.

I suggest you switch to using the Arduboy2 library and use ArduboyTones if you want to your sketch to produce sounds.

(Bryn) #3

Thanks, using Arduboy2 library works. I’m not anywhere near using sound/music yet myself, but my partner probably will be interested in it.
Seems like a bit oversight to me that the default library has this issue.
The idea of using the RGB LED for information display in a game is part of what made me want to get the Arduboy in the first place…
I don’t know this stuff well enough to make my own libraries yet, but maybe some day I will. My experience is mostly with javascript and I hate using things like jquery in lieu of writing functions myself.

Anyway, thanks for the help!

(Holmes) #4

I haven’t run into this issue and my Circuit Dude game doesn’t seem to have this problem. I use the digitalWrite(RED_LED, HIGH); function.

(Scott) #5

digitalWrite(), and also digitalWriteRGB() in the Arduboy2 library, won’t have a problem. They don’t use timer1 for PWM, which conflicts with the audio in the Arduboy library.

But controlling the LEDs digitally only gives full on or full off. That might be OK if you just flash them briefly, but you may get complaints of them being too bright otherwise. setRGBled() lets you vary the brightness of each LED, so you can set them dimmer and create lots of pretty colours (not just 7 pretty colours).

(Scott) #6

Yes it was an oversight. The RGB LED was added late in the game, after the audio code had already been written and nobody noticed the conflict until later.

Note that for 8000 or so Arduboys (the majority shipped to date) the green LED won’t work, and red and blue will be reversed and may appear at different intensities than a correct Arduboy using the same values. So I wouldn’t rely on the RGB LED being the only way that you convey certain information.