Arduboy2 - The now recommended alternative to the Arduboy Library

(Scott) #77

Then create a global instance of the Arduboy2 (or Arduboy2Base) class in the main .ino file, as normal:

#include <Arduboy2.h>

Arduboy2 arduboy;

In any other file (probably a .cpp) needing access to the arduboy instance, put:

#include <Arduboy2.h>

extern Arduboy2 arduboy;

(Simon) #78

I guess I could do that. Long live the global variable !

(Molly C) #79

If all the classes have a common base class you could have a static Arduboy2 arduboy; member in the base that is accessible to all the inherited classes. Then you only need to initialize that one static member.

(Scott) #80

Yes, that could work. However, you would have to do all Arduboy2 library access from functions within this single class hierarchy, since you shouldn’t create more than one instance of the Arduoby2 class in a sketch so as not to waste memory.

I suppose you could make the arduboy instance public, which means calls to Arduboy2 functions outside of the class hierarchy, could be done like:




(Scott) #81

16 posts were merged into an existing topic: Arduboy2 library paintScreen() optimisation

(Scott) #111

Arduboy2 library version 5.0.0 has been released and is available through the Arduino Library Manager.

As usual, one main goal was to make more code space available to sketches.

Release notes:

New features:

  • Classes BeepPin1 and BeepPin2 added. These can be used to play simple tones on the speaker. They are very code efficient.
  • New example sketch BeepDemo demonstrates the use of the BeepPin classes.
  • Class SpritesB added as an alternative to Sprites. This class has the same functions as Sprites but will produce less code in many cases (at the expense of slower execution speed). Thanks, @dxb (Delio Brignoli)
  • The ability to eliminate the USB code that is normally included in the Arduino environment. This will free up a significant amount of code space but will require the user to do a manual reset in order to upload a new sketch. Thanks, @Dreamer3 (Josh Goebel) for the concept.
  • The ability to set a flag in system EEPROM that will bypass the boot logo sequence and go straight to the sketch. New functions writeShowBootLogoFlag() and readShowBootLogoFlag() allow setting and reading this the flag.
  • Example sketch SetNameAndID has been renamed to SetSystemEEPROM. The ability to set the “show boot logo” flag has been added to it. It can now also be used to erase the entire system EEPROM or user EEPROM areas.
  • A new 2 parameter version of setRGBled() allows setting an individual RGB LED, given the color and brightness.
  • New function freeRGBled(). Using setRGBled() will take over the RGB LED pins so that digitalWriteRGB() will no longer work. Calling freeRGBled() will restore the pins for use by digitalWriteRGB().
  • New example sketch RGBled demonstrates the use of the RGB LED in both digital and analog modes.
  • New function setFrameDuration() can set the frame rate as the time per frame (in milliseconds), as an alternative to using setFrameRate() to set the frame rate in frames per second.
  • The loop at the end of the begin() function that waits for all buttons to be released has been replaced by function waitNoButtons(). This is to make it easier to add the functionality back in if boot() is used instead of begin().

Fixed a problem in the Sprites drawPlusMask() function that sometimes caused bitmaps to be drawn improperly. Thanks, @Dreamer3 (Josh Goebel)

The speed that the boot logo scrolls down has been increased, so that the actual sketch code begins faster.

The ArduBreakout example sketch has been modified to use the BeepPin1 class instead of Arduino tone().

Functions that have been refactored to optimize for size and usually speed:

  • paintScreen(), which is used by display(), has been re-written in assembler. Thanks, @Mr.Blinky and @veritazz (Michael Gollnick)
  • setRGBled() directly controls the hardware, instead of using the Arduino analogWrite() function.
  • bootLogoShell() and bootLogoText()
  • drawCompressed(). Thanks, @Pharap and @Mr.Blinky
  • buttonsState(). Thanks, @Mr.Blinky
  • nextFrame()
  • begin() (by using display() instead of blank() to clear the display).
  • idle()

Minor clarifications and corrections to previous and Doxygen documentation, plus:

  • Thanks, @eried (Erwin Ried) for correcting a typo in the everyXFrames() example code.
  • Added info on sketch EEPROM use to
  • Changed characters used for Sprites examples to make them more readable.

Some of the code savings available by using this release:

  • Just recompiling an existing sketch using this new release will reduce code size. Based on testing, typical savings will be about 150 bytes, compared to version 4.1.0, but it could be more or less depending on library functions that the sketch uses.

  • If a sketch uses more than one of the Sprites class functions, switching to SpritesB will save about 360 bytes, as long as the slower rendering speed of SpritesB is acceptable.

  • Sketches that currently use the setRGBled() function will see a significant reduction in code size, on the order of hundreds of bytes.

  • Removing the USB code will save about 2700 bytes or more but you should carefully consider if you need to do this, due to the inconvenience and possible frustration it can cause users because of the requirement to manually reset the Arduboy in order to upload a new sketch. Also, it’s recommended that some of the code freed up be used to add a menu item or prompt that allows the user to perform a reset using the DOWN button (by calling the new exitToBootloader() function).

Arduboy2 library update?
Guinea Pigs Wanted!
(Pharap) #112

One small oversight:
@Mr.Blinky suggested one of the changes to drawCompressed().

(Scott) #113

I’ve added @Mr.Blinky to the release notes on GitHub and in the post above. I’m sorry I can’t add him to the commit log because I don’t like to “rewrite history” after publicly and officially releasing.

(Pharap) #114

The post above was all I was expecting.

(Alex) #115

Whoa! My game went from this 10489 to 10368 bytes from recompile! thanks!

(Josh Goebel) #116

Great and detailed release notes!


Awesome to see a major update on the the Arduboy2 library @MLXXXp and thanks for the credits. Pleased that I could contribute. Looks like I have some work to do for the homemade version now :slight_smile:

(Scott) #118

Another appology: I realised I forgot to credit @Dreamer3 for the concept of how to remove the USB code. This has been corrected in the release notes (but unfortunately, again, I can’t add it to the git logs).

(Thomas) #119

I recompiled RogueBoy and gained over 1k bytes, Great work!

(Simon) #120

Yes great work @MLXXXp - now I can remove the setRGBled() code that you lent me with the real version!

(Michael Gollnick) #121

Super! Great work! I regained 106bytes in my project. :star_struck:

(Scott) #122

7 posts were split to a new topic: Sim-AVR problems with the new Arduboy2 V5

(Nicole Birgel) #123

Does this have any impact on existing software titles?

(Simon) #124

I don’t think so … the changes to existing functionality is just performance enhancements / code size reductions.

(Pharap) #126

The major version was increased so there should be at least one thing that breaks backwards compatibility.

That said, I can’t find it.
As far as I can tell all the changes are either bugfixes, new features or optimisations

The impact will be smaller/faster code.
(Assuming the games are recompiled with the new library.)