Last active
September 6, 2017 14:37
-
-
Save deejaygraham/26eb1865448bd69310caa528ad6a7f45 to your computer and use it in GitHub Desktop.
microbit heart animation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MicroBit.h" | |
MicroBit micro_bit; | |
const uint8_t empty_heart_bitmap[] { | |
0, 1, 0, 1, 0, | |
1, 0, 1, 0, 1, | |
1, 0, 0, 0, 1, | |
0, 1, 0, 1, 0, | |
0, 0, 1, 0, 0, }; | |
const uint8_t full_heart_bitmap[] { | |
0, 1, 0, 1, 0, | |
1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, | |
0, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, }; | |
const uint8_t small_heart_bitmap[] { | |
0, 0, 0, 0, 0, | |
0, 1, 1, 1, 0, | |
0, 1, 1, 1, 0, | |
0, 0, 1, 0, 0, | |
0, 0, 0, 0, 0, }; | |
const int screen_width = 5; | |
const int screen_height = 5; | |
MicroBitImage empty_heart(screen_width, screen_height, empty_heart_bitmap); | |
MicroBitImage full_heart(screen_width, screen_height, full_heart_bitmap); | |
MicroBitImage small_heart(screen_width, screen_height, small_heart_bitmap); | |
int main() | |
{ | |
micro_bit.init(); | |
while(1) | |
{ | |
micro_bit.display.print(full_heart); | |
micro_bit.sleep(1000); | |
micro_bit.display.print(small_heart); | |
micro_bit.sleep(1000); | |
micro_bit.display.print(empty_heart); | |
micro_bit.sleep(1000); | |
} | |
} | |
/* or this way | |
const int heart_w = 10; | |
const int heart_h = 5; | |
const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, }; | |
MicroBitImage i(heart_w,heart_h,heart); | |
display.animateAsync(i,100,5); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment