Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimatedDisplay animate - support negative stride #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martinwork
Copy link
Contributor

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();
}

@microbit-carlos
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants