Letter, points and light. Stars demo, scroll demo, flare demo, bounce demo

Dependencies:   microbit

MicroBit Graphics Demo

  • FunctionPointFlare();
  • FunctionBounceTest();
  • FunctionImageTest();
  • FunctionPrintTest();
  • FunctionStarTest();
  • FunctionImageScroll();

Functions.h

Committer:
MaxScorda
Date:
2019-06-02
Revision:
1:ed77b498d5c8
Child:
2:b767fa1c9241

File content as of revision 1:ed77b498d5c8:

void FunctionPointFlare()
{

    int  value = 64 ;
    for(int xx=-1 ; xx<=1; xx++) {
        for( int yy=-1; yy<=1; yy++) {
            uBit.display.image.setPixelValue(oldx+yy,oldy+xx, 0);
        }
    }


    for(int xx=-1 ; xx<=1; xx++) {
        for( int yy=-1; yy<=1; yy++) {
            uBit.display.image.setPixelValue(i+yy,k+xx, 2);
            //    uBit.serial.printf("%d - %d", yy,xx);
        }
    }
    uBit.display.image.setPixelValue(i,k, value);

    oldx=i;
    oldy=k;

    i=(i+sign);
    if ((i<0) || (i>4)) {
        sign=-sign;
        i=(i+sign);
        k++;
        k=k%5;
    }

    //  uBit.serial.printf("\nAccleremoter ");
    // uBit.serial.printf("x:%d  y:%d", uBit.accelerometer.getX(),uBit.accelerometer.getY());

    uBit.sleep(100);
}

void FunctionPrintTest()
{
    // uBit.display.scrollAsync("Scorda",500);
    uBit.display.printAsync("Scorda",500);
}

void FunctionImageTest()
{
    if (ccont%3==0)
        uBit.display.print(C);
    else if (ccont%3==1)
        uBit.display.print(Cb);
    else if (ccont%3==2)
        uBit.display.print(Cd);

    uBit.sleep(500);

}


void FunctionBounceTest()
{
    static int xx[]= {2,0,0};
    static int yy[]= {3,0,0};
    static int tempidx, idxvett=0;
    static int xost;
    static int yost;
    static int xcont=0;
    static int signx=1, signy=1;
    int value= 128;
    bool cambiay=false;
    int tempcolor;

    tempidx=idxvett;
    idxvett=(idxvett+1)%3;
    uBit.display.image.setPixelValue(xx[idxvett],yy[idxvett], 0);
    xx[idxvett]=(xx[tempidx]+signx)%5;
    yy[idxvett]=(yy[tempidx]+signy)%5;

    for(int i=0 ; i<=2; i++) {
        tempidx=(tempidx+i)%3;
        tempcolor=value/((i+1)*4);
        uBit.display.image.setPixelValue(xx[tempidx],yy[tempidx], tempcolor);
    }
//se sbatte sul punto ostacolo o ha fatto due
    if (((xx[idxvett]==xost)&&(yy[idxvett]==yost))||(xcont==2)) {
        uBit.display.image.setPixelValue(xost,yost, 0);
        if ((xx[idxvett]==xost)&&(yy[idxvett]==yost))
            cambiay=true;
        xost=rand()%5;
        yost=rand()%5;
        uBit.display.image.setPixelValue(xost,yost, value/4);
        xcont=0;
    }

    if ((yy[idxvett]==0) || (yy[idxvett]==4) || (cambiay==true)) {
        signy=-signy;
    }

    if ((xx[idxvett]==0) || (xx[idxvett]==4))
        signx=-signx;

    if (xx[idxvett]==0)
        xcont++;


    uBit.sleep(250);

}

void onButton(MicroBitEvent e)
{
    static bool premuto=false;
    int numfun=3;
    if ((e.source == MICROBIT_ID_BUTTON_A) && (premuto==false)) {
        sceltavar--;
        uBit.display.clear();
        uBit.serial.printf("\nBUTTON A: ");
    }

    if ((e.source == MICROBIT_ID_BUTTON_B)&& (premuto==false))  {
        sceltavar++;
        uBit.display.clear();
        uBit.serial.printf("\nBUTTON B: ");
    }

    if (e.value == MICROBIT_BUTTON_EVT_CLICK) {
        uBit.serial.printf("\nCLICK");
        premuto=true;
    }

    if (e.value == MICROBIT_BUTTON_EVT_HOLD) {
        uBit.serial.printf("\nHOLD");
        premuto=true;
    }
    if (e.value == MICROBIT_BUTTON_EVT_DOWN) {
        uBit.serial.printf("\nDOWN");
        premuto=true;
    }

    if (e.value == MICROBIT_BUTTON_EVT_UP) {
        uBit.serial.printf("UP");
        premuto=false;
    }

    sceltavar=(sceltavar+numfun)%numfun;
    uBit.serial.printf("--%d--", sceltavar);

}