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

Animate function does not work with negative stride #351

Open
microbit-mark opened this issue Apr 5, 2018 · 15 comments
Open

Animate function does not work with negative stride #351

microbit-mark opened this issue Apr 5, 2018 · 15 comments

Comments

@microbit-mark
Copy link
Contributor

When stride argument for the animatemethod has a neagtive value the micro:bit does nothing. We would expect it to animate in the opposite direction.
eg

#include "MicroBit.h"

MicroBit uBit;

int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();

    // Setup a simple triangular waveform.
    MicroBitImage img("1 0 0 0 0 0 0 0 0 1\n0 1 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 0 1 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n");

     uBit.display.animate(img, 200, -1);
}
@carlosperate
Copy link

Just to clarify @microbit-mark, when this code is run on a micro:bit nothing is displayed in the LED matrix, is that correct?

@microbit-mark
Copy link
Contributor Author

Yep. nothing is displayed on the micro:bit. Using uBit.display.animate(img, 200, 1); works

@finneyj
Copy link
Contributor

finneyj commented Apr 5, 2018

Thanks @microbit-mark and @carlosperate

Based on a quick scan of the code, it looks like you currently need to specify an explicit starting position if you want negative scrolling: https://github.com/lancaster-university/microbit-dal/blob/master/source/drivers/MicroBitDisplay.cpp#L934

Can you try your code again with the optional fourth parameter set, as indicated here:
https://lancaster-university.github.io/microbit-docs/ubit/display/#int-animate-microbitimage-image-int-delay-int-stride-int-startingposition

I guess it will be roughly -the_width_of_your_image ...

@microbit-mark
Copy link
Contributor Author

I've tried variations on uBit.display.animate(img, 200, -1,-10) but can't get a working example of negative scrolling animation using the waveform sample.

@microbit-mark
Copy link
Contributor Author

@finneyj anything else I can try?

@microbit-pauline
Copy link

Assigning to @microbit-sam as a BAU DAL activity

@microbit-mark
Copy link
Contributor Author

Had another request in support for this, so polling the issue.

@microbit-mark
Copy link
Contributor Author

micro:bit support: 20935
Another support request for this issue

@martinwork
Copy link
Contributor

I think I have fixed this. I'll make a PR.

@microbit-mark
Copy link
Contributor Author

micro:bit support: 38373
Another support request re this issue
Are we able to merge the fix?

@microbit-mark
Copy link
Contributor Author

Raised again in microbit support: 42107

@microbit-mark
Copy link
Contributor Author

Raised in microbit support: 44708 Also reproduces on V2. @martinwork does your PR #427 still apply for both board variants? This would be a good one to progress as it crops up every so often.

@martinwork
Copy link
Contributor

@microbit-mark V2 and V1 look the same with negative stride, using the test below, so hopefully the changes needed in CODAL would be similar. Would you like a PR like this for the DAL js-event-semantics branch and one for CODAL?

#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");


void onButtonA(MicroBitEvent e)
{
    int stride = -1;
    uBit.display.stopAnimation();
    uBit.display.clear();
    uBit.display.animate(img, 1000, stride, 2, 0);
}


void onButtonB(MicroBitEvent e)
{
    int stride = 1;
    uBit.display.stopAnimation();
    uBit.display.clear();
    uBit.display.animate(img, 1000, 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);

    release_fiber();
}

@microbit-mark
Copy link
Contributor Author

Raised again in micro:bit support: 46440

@martinwork

Would you like a PR like this for the DAL js-event-semantics branch and one for CODAL?

It would be great to fix this for all board variants . I'll leave the prioritisation with you and @finneyj as to where and when.

@martinwork
Copy link
Contributor

DAL js-event-semantics branch: #485
CODAL: lancaster-university/codal-core#145

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

No branches or pull requests

5 participants