Skip to content

Instantly share code, notes, and snippets.

@deejaygraham
Last active September 6, 2017 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deejaygraham/26eb1865448bd69310caa528ad6a7f45 to your computer and use it in GitHub Desktop.
Save deejaygraham/26eb1865448bd69310caa528ad6a7f45 to your computer and use it in GitHub Desktop.
microbit heart animation example
#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