/*******************************************************************************
    PocketScreen Screen Hello World Example
    written by Florian Keller
    last changed 05 Dec 20

    Prints 'Hello world' onto the screen, in alternating colors.
*******************************************************************************/

// we need the library
#include <PocketScreen.h>
PocketScreen pocketscreen = PocketScreen();

// the text will cycle through these colors
#define NUM_COLORS 7
uint16_t colors[NUM_COLORS] = {YELLOW_16b, ORANGE_16b, RED_16b, MAGENTA_16b, BLUE_16b, CYAN_16b, GREEN_16b};

void setup() {
    // initialize screen and set bit depth to 16
    pocketscreen.begin();
    pocketscreen.setBitDepth(BitDepth16);

    // set font
    pocketscreen.setFont(pocketScreen7pt);
}

void loop() {
    // loop through color array
    for (int i = 0; i < NUM_COLORS; i++) {
        // print text
        printToScreen(colors[i]);
        // wait 0.5 seconds
        delay(500);
    }
}

// helper function which draws 'Hello World!' in the specified color
void printToScreen(uint16_t color) {
    // clear screen
    pocketscreen.drawRect(0, 0, 96, 16, true, BLACK_16b);

    // set color
    pocketscreen.setFontColor(color, BLACK_16b);

    // print to top-middle (48 = half screen width)
    pocketscreen.setCursor(48 - pocketscreen.getPrintWidth("Hello World!")/2, 16);
    pocketscreen.print("Hello World!");
}
