Nibble errors

This is a post for all of my bugs in nibble programming, I will have a lot.

Bug #1:

This code only shows up as a black screen. Is it looping and clearing too fast?

// cm:esp8266:nibble
// cm:esp8266:nibble
#include <Arduino.h>
#include <CircuitOS.h>
#include <Nibble.h>

bool up,down,left,right,a,b,menu;

Display* display;
Sprite* sprite;

//auto colors[] = {TFT_BLACK,TFT_RED,TFT_GREEN,TFT_BLUE,TFT_YELLOW,TFT_CYAN,TFT_MAGENTA,TFT_WHITE};
int icons[] = {
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};

void BTN_UP_press(){up = true;}
void BTN_UP_release(){up = false;}
void BTN_DOWN_press(){down = true;}
void BTN_DOWN_release(){down = false;}
void BTN_LEFT_press(){left = true;}
void BTN_LEFT_release(){left = false;}
void BTN_RIGHT_press(){right = true;}
void BTN_RIGHT_release(){right = false;}
void BTN_A_press(){a = true;}
void BTN_A_release(){a = false;}
void BTN_B_press(){b = true;}
void BTN_B_release(){b = false;}
void BTN_C_press(){menu = true;}
void BTN_C_release(){menu = false;}

void setup() {
    Nibble.begin();
    display = Nibble.getDisplay();
    sprite = display->getBaseSprite();

    Input::getInstance()->setBtnPressCallback(BTN_UP, BTN_UP_press);
    Input::getInstance()->setBtnReleaseCallback(BTN_UP, BTN_UP_release);
    Input::getInstance()->setBtnPressCallback(BTN_DOWN, BTN_DOWN_press);
    Input::getInstance()->setBtnReleaseCallback(BTN_DOWN, BTN_DOWN_release);
    Input::getInstance()->setBtnPressCallback(BTN_LEFT, BTN_LEFT_press);
    Input::getInstance()->setBtnReleaseCallback(BTN_LEFT, BTN_LEFT_release);
    Input::getInstance()->setBtnPressCallback(BTN_RIGHT, BTN_RIGHT_press);
    Input::getInstance()->setBtnReleaseCallback(BTN_RIGHT, BTN_RIGHT_release);
    Input::getInstance()->setBtnPressCallback(BTN_A, BTN_A_press);
    Input::getInstance()->setBtnReleaseCallback(BTN_A, BTN_A_release);
    Input::getInstance()->setBtnPressCallback(BTN_B, BTN_B_press);
    Input::getInstance()->setBtnReleaseCallback(BTN_B, BTN_B_release);
    Input::getInstance()->setBtnPressCallback(BTN_C, BTN_C_press);
    Input::getInstance()->setBtnReleaseCallback(BTN_C, BTN_C_release);

    up = false;
    down = false;
    left = false;
    right = false;
    a = false;
    b = false;
    menu = false;
}

void loop() {
    Input::getInstance()->loop(0);

    sprite->clear(TFT_BLACK);
    for(int y=0;y<16;y++){
      for(int x=0;x<16;x++){
        if(icons[y*16+x]==0){
          sprite->fillRect(x, y, 1, 1, TFT_BLACK);
        }else if(icons[y*16+x]==1){
          sprite->fillRect(x, y, 1, 1, TFT_RED);
        }else if(icons[y*16+x]==2){
          sprite->fillRect(x, y, 1, 1, TFT_GREEN);
        }else if(icons[y*16+x]==3){
          sprite->fillRect(x, y, 1, 1, TFT_BLUE);
        }else if(icons[y*16+x]==4){
          sprite->fillRect(x, y, 1, 1, TFT_CYAN);
        }else if(icons[y*16+x]==5){
          sprite->fillRect(x, y, 1, 1, TFT_MAGENTA);
        }else if(icons[y*16+x]==6){
          sprite->fillRect(x, y, 1, 1, TFT_YELLOW);
        }else{
          sprite->fillRect(x, y, 1, 1, TFT_WHITE);
        }
      }
    }
    display->commit();
}

It’s probably a silly error like forgetting a method :woozy_face:

I think you have to display->commit() after each sprite->fillRect()

@Tizzlerbot76 thanks for helping out :slight_smile: