Binary counter from 0 to (2^25)-1 with wraparound. Bits are displayed on the LED matrix, filling from bottom right. Press buttonA for a decimal representation of the current counter value.

Dependencies:   microbit

main.cpp

Committer:
davidrainford
Date:
2018-07-24
Revision:
0:f5e7d4075c2a

File content as of revision 0:f5e7d4075c2a:

#include "MicroBit.h"

MicroBit uBit;

int main()
{
    char col[25] = {4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0};
    char row[25] = {4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
    int i, count = 0;
    uBit.init();
    while (1) {
        for (i = 0; i < 25; i++) {
            uBit.display.image.setPixelValue(col[i], row[i], ((count >> i) & 1) * 255);
        }
        if (uBit.buttonA.isPressed()) {
            uBit.display.scroll(count);
        }
        count = count++ & 33554431;
    }
}