lancaster-university / microbit-dal

http://lancaster-university.github.io/microbit-docs
Other
256 stars 130 forks source link

MicroBitDisplay animate - support negative stride for js-event-semantics branch #485

Open martinwork opened 2 years ago

martinwork commented 2 years ago

startingPosition refers to the leading edge

Test program:

#include "MicroBit.h"

MicroBit uBit;

MicroBitImage img("255 0 0 0 0 0 0 0 0 255\n"
                  "0 255 0 0 0 0 0 0 255 0\n"
                  "0 0 255 0 0 0 0 255 0 0\n"
                  "0 0 0 255 0 0 255 0 0 0\n"
                  "0 0 0 0 255 255 0 0 0 0\n");

int stride = 1;

void onButtonA(MicroBitEvent e)
{
    stride = -1;
    uBit.display.stopAnimation();
}

void onButtonB(MicroBitEvent e)
{
    stride = 1;
    uBit.display.stopAnimation();
}

void forever()
{
    while ( true)
    {
      uBit.display.stopAnimation();
      uBit.display.clear();
      uBit.display.animate(img, 500, stride, MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, 0);

      uBit.display.stopAnimation();
      uBit.display.clear();
      uBit.display.animate(img, 500, stride, 2, 0);
    }
}

int  main()
{
    uBit.init();

    uBit.messageBus.listen( MICROBIT_ID_BUTTON_A,  MICROBIT_BUTTON_EVT_CLICK, onButtonA);
    uBit.messageBus.listen( MICROBIT_ID_BUTTON_B,  MICROBIT_BUTTON_EVT_CLICK, onButtonB);

    create_fiber( forever);

    release_fiber();
}
carlosperate commented 2 years ago

Hi Martin, thanks for the PR! Is this different to https://github.com/lancaster-university/microbit-dal/pull/427/?

martinwork commented 2 years ago

It should be the same except targeted at the js-event-semantics branch.