Skip to content

Commit 1ee2b40

Browse files
committed
Make the heart in love module beat like a real heart.
1 parent 5b31075 commit 1ee2b40

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

source/microbit/modlove.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,27 @@ extern "C" {
3535
#include "microbitdisplay.h"
3636

3737
static const mp_float_t bright[7] = {
38-
0.0, 1.0/9, 2.0/9, 4.0/9, 6.0/9, 7.0/9, 8.0/9
38+
0.0, 1.0/9, 2.0/9, 4.0/9, 6.0/9, 7.0/9, 1.0,
3939
};
4040

41-
void love(int interval = 80 /* ms */) {
42-
microbit_image_obj_t * hearts[7];
43-
for (int i = 0; i < 7; i++) {
41+
void love(int interval = 25 /* ms */) {
42+
microbit_image_obj_t *hearts[MP_ARRAY_SIZE(bright)];
43+
for (uint i = 0; i < MP_ARRAY_SIZE(bright); i++) {
4444
hearts[i] = microbit_image_dim(HEART_IMAGE, bright[i]);
4545
}
4646

47-
for(int iteration = 0; iteration < 5; iteration++) {
48-
for(int step = 0; step < 7; ++step) {
47+
for (int iteration = 0; iteration < 8; iteration++) {
48+
// pause between double beats of the heart
49+
if (iteration && (iteration & 1) == 0) {
50+
mp_hal_delay_ms(20 * interval);
51+
}
52+
// pulse heart to max brightness
53+
for(uint step = 0; step < MP_ARRAY_SIZE(bright); ++step) {
4954
microbit_display_print(&microbit_display_obj, hearts[step]);
5055
mp_hal_delay_ms(interval);
5156
}
52-
for(int step = 6; step >= 0; --step) {
57+
// pulse heart to min brightness
58+
for(int step = MP_ARRAY_SIZE(bright) - 1; step >= 0; --step) {
5359
microbit_display_print(&microbit_display_obj, hearts[step]);
5460
mp_hal_delay_ms(interval);
5561
}

0 commit comments

Comments
 (0)