@@ -35,21 +35,27 @@ extern "C" {
35
35
#include " microbitdisplay.h"
36
36
37
37
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 ,
39
39
};
40
40
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++) {
44
44
hearts[i] = microbit_image_dim (HEART_IMAGE, bright[i]);
45
45
}
46
46
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) {
49
54
microbit_display_print (µbit_display_obj, hearts[step]);
50
55
mp_hal_delay_ms (interval);
51
56
}
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) {
53
59
microbit_display_print (µbit_display_obj, hearts[step]);
54
60
mp_hal_delay_ms (interval);
55
61
}
0 commit comments