0

Using this basic example code from microbit, blinking heart, I tried to change the delay of blinking with the pause argument. However, the minimum actual blinking frequency is around 500ms, no matter what value i put.

Do you know why, and how I can achieve much faster blinking with led patterns (like show_icon or show_leds function).

def on_forever():
    basic.show_icon(IconNames.HEART)
    basic.pause(50)
    basic.show_icon(IconNames.SMALL_HEART)
    basic.pause(50)
basic.forever(on_forever)

Thanks.

agenis
  • 8,069
  • 5
  • 53
  • 102

1 Answers1

3

You have tagged this as micropython but I don't believe that is what you are using. I think you are running with the Python in the MakeCode editor.

Looking at the help page for for the MakeCode show_icon, it says it is called with:

def basic.show_icon(icon: IconNames, interval: null): None

with the following details about interval:

interval (optional), the time to display in milliseconds. default is 600.

As you were not putting a value for interval it was defaulting to 600 milliseconds which meant your code was putting 650 milliseconds delay between each icon.

I was able to vary the duration an icon was displayed with the following:

def on_forever():
    basic.show_icon(IconNames.HEART, 100)
    basic.show_icon(IconNames.SMALL_HEART, 400)
    basic.show_icon(IconNames.HEART, 100)
    basic.show_icon(IconNames.SMALL_HEART, 800)

basic.forever(on_forever)

ukBaz
  • 6,985
  • 2
  • 8
  • 31
  • Thanks, you're right! Actually it seems that the interval option does not exist on the block coding interface. You have to choose python to use it. Anyway, i think other people might come into the same problem, thanks for the answer. – agenis May 09 '21 at 13:26