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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "MicroBit.h"
00002 
00003 MicroBit uBit;
00004 
00005 int main()
00006 {
00007     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};
00008     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};
00009     int i, count = 0;
00010     uBit.init();
00011     while (1) {
00012         for (i = 0; i < 25; i++) {
00013             uBit.display.image.setPixelValue(col[i], row[i], ((count >> i) & 1) * 255);
00014         }
00015         if (uBit.buttonA.isPressed()) {
00016             uBit.display.scroll(count);
00017         }
00018         count = count++ & 33554431;
00019     }
00020 }