### Initialize Arduboy2 Library in setup() Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Illustrates the essential step of calling the `begin()` function within the sketch's `setup()` function to initialize the Arduboy2 library. This prepares the library for use. ```cpp void setup() { arduboy.begin(); // more setup code follows, if required } ``` -------------------------------- ### Initialize ArduboyPlaytune Object Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Creates an instance of the ArduboyPlaytune class, passing a pointer to the Arduboy2 audio enabled function. This setup is required after creating the main Arduboy2 object. ```cpp Arduboy2 arduboy; ArduboyPlaytune tunes(arduboy.audio.enabled); ``` -------------------------------- ### Initialize Audio Channels Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Sets up sound channels for the ArduboyPlaytune library within the setup() function. It includes conditional logic for DevKit boards to manage speaker pins and mute scores during tones. ```cpp // audio setup tunes.initChannel(PIN_SPEAKER_1); #ifndef AB_DEVKIT // if not a DevKit tunes.initChannel(PIN_SPEAKER_2); #else // if it's a DevKit tunes.initChannel(PIN_SPEAKER_1); // use the same pin for both channels tunes.toneMutesScore(true); // mute the score when a tone is sounding #endif ``` -------------------------------- ### Basic Arduboy Boot Feature Substitution Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md This snippet demonstrates replacing the standard arduboy.begin() call with arduboy.boot() and manually including essential boot-up features like flashlight(), systemButtons(), audio.begin(), and bootLogo() in the setup() function. It highlights the trade-offs for code space and the necessity of functions like flashlight() or safeMode() for bootloader recovery. ```cpp void setup() { // Required to initialize the hardware. arduboy.boot(); // This clears the display. (The screen buffer will be all zeros) // It may not be needed if something clears the display later on but // "garbage" will be displayed if systemButtons() is used without it. arduboy.display(); // flashlight() or safeMode() should always be included to provide // a method of recovering from the bootloader "magic key" problem. arduboy.flashlight(); // arduboy.safeMode(); // This allows sound to be turned on or muted. If the sketch provides // its own way of toggling sound, or doesn't produce any sound, this // function may not be required. arduboy.systemButtons(); // This is required to initialize the speaker. It's not needed if // the sketch doesn't produce any sounds. arduboy.audio.begin(); // This displays the boot logo sequence but note that the logo can // be suppressed by the user, by pressing the RIGHT button or using // a system EEPROM setting. If not removed entirely, an alternative // bootLogo...() function may save some memory. arduboy.bootLogo(); // arduboy.bootLogoCompressed(); // arduboy.bootLogoSpritesSelfMasked(); // arduboy.bootLogoSpritesOverwrite(); // arduboy.bootLogoSpritesBSelfMasked(); // arduboy.bootLogoSpritesBOverwrite(); // arduboy.bootLogoText(); // Wait for all buttons to be released, in case a pressed one might // cause problems by being acted upon when the actual sketch code // starts. If neither systemButtons() nor bootLogo() is kept, this // function isn't required. arduboy.waitNoButtons(); // Additional setup code... } ``` -------------------------------- ### Custom Arduboy Boot Logo with Compressed Bitmap Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md This example shows how to create a custom boot logo function that utilizes a compressed bitmap drawing routine, such as ardubyte.drawCompressed(). It defines a drawing function and a boot logo function that calls it, then integrates this custom boot logo into the setup() function, demonstrating advanced code space optimization. ```cpp void drawLogoArdCompressed(int16_t y) { ardbitmap.drawCompressed(20, y, arduboy_logo_ardbitmap, WHITE, ALIGN_CENTER, MIRROR_NONE); } void bootLogoArdCompressed() { if (arduboy.bootLogoShell(drawLogoArdCompressed)) { arduboy.bootLogoExtra(); } } void setup() { arduboy.beginDoFirst(); bootLogoArdCompressed(); arduboy.waitNoButtons(); // Additional setup code... } ``` -------------------------------- ### Commit Message Style: Refactoring Example Source: https://github.com/mlxxxp/arduboy2/blob/master/CONTRIBUTING.md This example demonstrates a commit message for refactoring code and adding new functionality. It includes a subject line and a detailed body with bullet points explaining the changes. ```git Refactor text code and add char size functions - Functions write() and drawChar() were refactored for smaller code size and to make text wrapping operate more like what would normally be expected. - A new flag variable, textRaw, has been added, along with functions setTextRawMode() and getTextRawMode() to set and read it. ``` -------------------------------- ### Build Cabi for Windows Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/cabi/README.md Example build command for Windows systems, specifying the output executable name as CABI.EXE. It uses GCC and links the necessary C source files. ```shell gcc cabi.c lodepng/lodepng.c -o CABI.EXE ``` -------------------------------- ### Commit Message Style: Body and Details Source: https://github.com/mlxxxp/arduboy2/blob/master/CONTRIBUTING.md Following the subject line, a blank line should separate it from the detailed explanation. The body should provide further context, explain the 'why' behind the changes, and wrap lines at a maximum of 72 characters. Bullet points, if used, should have a hanging indent. ```git The variables currentButtonState and previousButtonState used by pollButtons(), justPressed() and justReleased() have been made public. This allows them to be manipulated if circumstances require it. The documentation added for previousButtonState includes an example. ``` -------------------------------- ### Cabi Command-Line Conversion Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/cabi/README.md Example of using the Cabi tool to convert an image file (e.g., PlayerSprite.png) into C/C++ byte arrays and redirecting the output to a file. The output contains C/C++ code for image and mask arrays. ```Shell cabi PlayerSprite.png PlayerSprite > PlayerSprite.out ``` -------------------------------- ### Commit Message Style: Subject Line Source: https://github.com/mlxxxp/arduboy2/blob/master/CONTRIBUTING.md The first line of a commit message should be a concise summary, limited to 50 characters. It should be written as a capitalized imperative sentence, clearly stating the action performed by the commit. ```git Make state variables used by pollButtons() public ``` -------------------------------- ### Arduboy2 Initialization and Boot Process Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md The beginNoLogo() function from Arduboy V1.1 is not included. Instead, Arduboy2 provides a boot() function, allowing sketches to add specific features after booting if needed. ```APIDOC boot() - Initializes the Arduboy hardware. This replaces the basic initialization part of begin(). // Example usage to replicate begin() functionality without logo: // boot(); // display.clear(); // drawBitmap(..., WHITE); // etc. ``` -------------------------------- ### Replace beginNoLogo() with begin() Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Shows how to replace the removed beginNoLogo() function with begin() or a combination of beginDoFirst() and waitNoButtons() to achieve similar boot behavior. ```cpp // Equivalent replacement for arduboy.beginNoLogo(): arduboy.beginDoFirst(); arduboy.waitNoButtons(); ``` -------------------------------- ### Instantiate Arduboy2 Class Object Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Shows how to create an instance of the Arduboy2 class. Naming the object 'arduboy' is a common convention, but any valid identifier can be used. ```cpp Arduboy2 arduboy; ``` -------------------------------- ### Migrate to ArduboyTones Library for Sound Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md This method involves integrating the ArduboyTones library to manage sound playback. It requires adding a new include, instantiating the ArduboyTones class with a pointer to arduboy.audio.enabled, and changing tune calls to the new library's methods. ```cpp #include // After Arduboy2 object creation: Arduboy2 arduboy; ArduboyTones sound(arduboy.audio.enabled); // Example usage change: // arduboy.tunes.tone(1000, 250); // becomes // sound.tone(1000, 250); ``` -------------------------------- ### Include Arduboy2 Header File Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Demonstrates how to include the Arduboy2 library header file at the beginning of an Arduino sketch. This is the first step to using the library's functionalities. ```cpp #include ``` -------------------------------- ### Instantiate Sprites Class Object Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Demonstrates how to create an instance of the `Sprites` class if you intend to use its sprite rendering functions. This is separate from the main Arduboy2 object. ```cpp Sprites sprites; ``` -------------------------------- ### Cabi Usage Syntax Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/cabi/README.md Displays the command-line usage syntax for the Cabi program. It shows the required input PNG file and an optional prefix for the generated C/C++ array names. ```shell cabi - Compress Arduboy Image Convert a PNG file into RLE encoded C/C++ source for use with Arduboy2 drawCompressed() usage: cabi in.png [array_name_prefix] ``` -------------------------------- ### Build Cabi with Clang Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/cabi/README.md Compiles the Cabi program using Clang, linking the main cabi.c file with the lodepng.c library for PNG handling. The output executable is named 'cabi'. ```shell clang cabi.c lodepng/lodepng.c -o cabi ``` -------------------------------- ### Build Cabi with GCC Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/cabi/README.md Compiles the Cabi program using GCC, linking the main cabi.c file with the lodepng.c library for PNG handling. The output executable is named 'cabi'. ```shell gcc cabi.c lodepng/lodepng.c -o cabi ``` -------------------------------- ### Include ArduboyPlaytune Library Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Adds the necessary header file for the ArduboyPlaytune library, which provides functionality similar to the removed tunes subclass from Arduboy V1.1. ```cpp #include ``` -------------------------------- ### Update tunes.playScore() Calls Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Demonstrates how to refactor existing code that uses the Arduboy object's tunes.playScore() method to use the standalone ArduboyPlaytune object. ```cpp // Original call: // arduboy.tunes.playScore(mySong); // Refactored call: tunes.playScore(mySong); ``` -------------------------------- ### Arduboy2 Text Function Enhancements Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Arduboy2 expands text output capabilities with new functions for setting text colors and retrieving cursor positions. The clear() function also has a modified behavior. ```APIDOC setTextColor(color, background_color) - Sets the color for text and its background. - Parameters: - color: The foreground color for text. - background_color: The background color for text. setTextBackground(background_color) - Sets the background color for text. - Parameters: - background_color: The background color for text. getCursorX() - Returns the current X position of the text cursor. - Returns: The current X coordinate. getCursorY() - Returns the current Y position of the text cursor. - Returns: The current Y coordinate. clear() - Clears the screen and resets the text cursor to the home position (0, 0). ``` -------------------------------- ### Arduboy2 RGB LED Control Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Arduboy2 offers a new method for digital control of the RGB LED, which can save code space compared to PWM methods when only full on/off states are needed. ```APIDOC digitalWriteRGB(red, green, blue) - Controls the RGB LED digitally. - Parameters: - red: Set to HIGH to turn red LED on, LOW to turn off. - green: Set to HIGH to turn green LED on, LOW to turn off. - blue: Set to HIGH to turn blue LED on, LOW to turn off. ``` -------------------------------- ### Arduboy2 Library Version in library.properties Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/docs/VERSIONING.txt Specifies the Arduboy2 library version in the `library.properties` file. This format is standard for Arduino libraries, indicating the version for IDE integration and management. ```properties version= ``` -------------------------------- ### Replace tunes.tone() with Arduino tone() Wrapper Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md This solution involves replacing calls to arduboy.tunes.tone() with a custom playTone() function that wraps the Arduino built-in tone() function. This wrapper also checks if audio is enabled in Arduboy2 before playing sound. ```cpp // Wrap the Arduino tone() function so that the pin doesn't have to be // specified each time. Also, don't play if audio is set to off. void playTone(unsigned int frequency, unsigned long duration) { if (arduboy.audio.enabled() == true) { tone(PIN_SPEAKER_1, frequency, duration); } } // Example usage change: // arduboy.tunes.tone(1000, 250); // becomes // playTone(1000, 250); ``` -------------------------------- ### Use SpritesB for Code Size Optimization Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md The SpritesB class offers identical functionality to the Sprites class but is optimized for smaller code size rather than execution speed. This snippet demonstrates how to switch between the two classes by changing the object instantiation, allowing developers to choose based on their project's needs. ```cpp Sprites sprites; // Use this to optimize for execution speed SpritesB sprites; // Use this to (likely) optimize for code size ``` -------------------------------- ### Arduboy2 Library Version in Doxyfile Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/docs/VERSIONING.txt Sets the project version number for Doxygen documentation generation in the `Doxyfile` configuration file. This ensures the version is correctly displayed in generated API documentation. ```text PROJECT_NUMBER = ``` -------------------------------- ### Update Library Include Directive Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Change the Arduboy library include directive from to for compatibility with the Arduboy2 library. This is a fundamental step in the migration process. ```cpp #include // becomes #include ``` -------------------------------- ### Arduboy2 Library Version in library.json Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/docs/VERSIONING.txt Defines the Arduboy2 library version within a JSON configuration file. This is often used for package management, metadata, and more structured project configurations. ```json "version": ``` -------------------------------- ### Update Library Object Instantiation Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Modify the instantiation of the Arduboy object to use the Arduboy2 class. This ensures the sketch correctly initializes the Arduboy2 library features. If a different object name was used, retain it. ```cpp Arduboy arduboy; // becomes Arduboy2 arduboy; ``` -------------------------------- ### Arduboy2 Library Version Macro in Arduboy2.h Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/docs/VERSIONING.txt Defines the Arduboy2 library version using a C/C++ preprocessor macro in the main header file. This allows the version to be accessed programmatically within the library's code. ```c++ #define ARDUBOY_LIB_VER ``` -------------------------------- ### Eliminate USB Stack Code Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md This section explains how to remove the USB stack code from an Arduboy2 sketch using the ARDUBOY_NO_USB macro. It warns that this requires manual reset for uploading new sketches and introduces the exitToBootloader() function for easier bootloader invocation. This technique frees up significant code and RAM space but should be used cautiously. ```cpp // Define ARDUBOY_NO_USB to eliminate USB stack code // #define ARDUBOY_NO_USB // Function to manually invoke the bootloader // void exitToBootloader(); ``` -------------------------------- ### Arduboy2 Masked Drawing with Cabi Output Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/cabi/README.md Demonstrates how to include Cabi-generated image and mask byte arrays in an Arduboy2 sketch and use the drawCompressed() function for masked image display. The first call draws the mask with BLACK, and the second draws the image with WHITE. ```C++ #include Arduboy2 arduboy; // ===== Cabi output ===== // sample.png width: 32 height: 32 const PROGMEM uint8_t sample[] = { 0x1f,0x1f,0x68,0x93,0xca,0x39,0xe5,0x9c,0x72,0xca,0xe9,0x74,0x4b,0x25,0x95,0xdc, 0x6e,0xb7,0xdb,0xed,0x56,0x49,0x65,0xb7,0x4a,0x3a,0xa9,0xac,0x92,0x4e,0x3a,0xa9, 0x74,0x94,0x8c,0x6a,0xbb,0xdd,0x6e,0xb7,0x8c,0x76,0xbb,0xdd,0x6e,0xb7,0xdb,0xed, 0x76,0xbb,0xdd,0xf2,0xf1,0xa6,0xb7,0x52,0x79,0xc5,0xa4,0xbc,0x92,0x76,0x1d,0x2f, 0x9f,0xdd,0x6e,0xb7,0xdb,0xed,0x76,0xbb,0xdd,0x6e,0xb7,0x8c,0xf4,0xd9,0x15,0x23, 0x65,0x5a,0x49,0x27,0x9d,0x54,0x56,0x49,0x27,0x95,0xdd,0x2a,0xa9,0xec,0x76,0xbb, 0xdd,0x6e,0x97,0x4a,0x2a,0xb9,0x54,0xce,0x39,0xe5,0x94,0x73,0xca,0x39,0x25,0xa3, 0x05 }; // bytes:113 ratio: 0.883 const PROGMEM uint8_t sample_mask[] = { 0x1f,0x1f,0x68,0x93,0xca,0x39,0x25,0x95,0xdc,0xa6,0xd3,0xa1,0x35,0x9d,0x4e,0x6f, 0x95,0x54,0xd2,0x39,0xa9,0x74,0x94,0xe8,0xb4,0xdb,0xed,0x76,0xbb,0xdd,0x6e,0xb7, 0xdb,0xed,0x16,0x8f,0x8a,0x49,0xe1,0xd1,0x6e,0xb7,0xdb,0xed,0x76,0xbb,0xdd,0x6e, 0xb7,0x5b,0x74,0x52,0xa6,0x95,0x74,0x4e,0x2a,0xa9,0xec,0x3a,0x9d,0x0e,0xad,0xe9, 0x74,0x76,0xa9,0xa4,0x72,0x4e,0xc9,0x68,0x01 }; // bytes:73 ratio: 0.570 // ======================= void setup() { arduboy.begin(); } void loop() { arduboy.clear(); arduboy.drawCompressed(20, 10, sample_mask, BLACK); arduboy.drawCompressed(20, 10, sample, WHITE); arduboy.display(); } ``` -------------------------------- ### Arduboy2 Drawing Function Color Parameter Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md The 'color' parameter in most drawing functions is now optional and defaults to WHITE if omitted, providing convenience for common use cases. ```APIDOC drawPixel(x, y, color) - Draws a pixel at the specified coordinates. The color parameter is optional and defaults to WHITE. drawLine(x1, y1, x2, y2, color) - Draws a line between two points. The color parameter is optional and defaults to WHITE. drawRect(x, y, width, height, color) - Draws a rectangle. The color parameter is optional and defaults to WHITE. fillRect(x, y, width, height, color) - Fills a rectangle. The color parameter is optional and defaults to WHITE. drawCircle(x, y, radius, color) - Draws a circle. The color parameter is optional and defaults to WHITE. fillCircle(x, y, radius, color) - Fills a circle. The color parameter is optional and defaults to WHITE. ``` -------------------------------- ### Use Arduboy2Base to Remove Text Functions Source: https://github.com/mlxxxp/arduboy2/blob/master/README.md Replace the standard Arduboy2 object with Arduboy2Base to eliminate text rendering functions and associated font tables. This is beneficial for sketches that generate text via alternative methods, optimizing code size. ```cpp For example, if the object will be named *arduboy*: Replace ```cpp Arduboy2 arduboy; ``` with ```cpp Arduboy2Base arduboy; ``` ``` -------------------------------- ### Arduboy2 drawCompressed() Function Source: https://github.com/mlxxxp/arduboy2/blob/master/extras/cabi/README.md API documentation for the Arduboy2 library's drawCompressed() function. This function draws a bitmap stored as a compressed byte array. It supports masked drawing by calling it twice with different arrays and colors. ```APIDOC Arduboy2::drawCompressed(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t color) Draws a compressed bitmap at the specified coordinates. Parameters: x: The x-coordinate (column) for the top-left corner of the bitmap. y: The y-coordinate (row) for the top-left corner of the bitmap. bitmap: A pointer to the PROGMEM byte array containing the compressed bitmap data. The data format includes dimensions and compressed pixel data. color: The color to draw the bitmap pixels. Typically WHITE (1) for the image and BLACK (0) for the mask when performing masked drawing. Description: This function is used to display images that have been compressed using tools like Cabi. It decodes the compressed data on the fly and draws it to the Arduboy's screen buffer. For masked drawing, it's recommended to call this function twice: 1. Draw the mask array with BLACK to clear the background pixels. 2. Draw the actual image array with WHITE over the cleared area. Related Methods: - Arduboy2::clear(): Clears the screen buffer. - Arduboy2::display(): Updates the physical screen with the buffer content. Example Usage: // Assuming 'sample' is the image array and 'sample_mask' is the mask array arduboy.drawCompressed(20, 10, sample_mask, BLACK); arduboy.drawCompressed(20, 10, sample, WHITE); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.