paulober/MicroPico

Code Quirk?

deebz opened this issue · 1 comments

Hello, sorry this isn't a bug as such - more of a question.

I'm just learning micropython and would prefer to use VSCode over thonny as I prefer the IDE from past experience.

However I have noticed that there is slight difference in how the code is being executed on the pico between the two IDE's, though I don't know if that's because of the code example I'm following or if it's a quirk of MicroPico. So if anyone can give a pointer, that would be great.

Essentially the issue surrounds this simple dice program written originally by Simon Monk (below) featured in his book Programming the Pico. This code runs as expected in Thonny, but the input() line doesn't exhibit the same behviour when using micropico. Hitting enter in the terminal just brings back an empty prompt again.

from machine import Pin
from utime import sleep
from random import randint

led = Pin('LED', Pin.OUT)

def throw_dice():
    return randint(1, 6)

def blink(times, delay):
    for x in range(1, times+1):
        led.on()
        sleep(delay)
        led.off()
        sleep(delay)
      
while True:
    input() # Pauses program until user presses enter
    dice_throw = throw_dice()
    print(dice_throw)
    blink(dice_throw, 0.2)

I'm using a Mac, Raspberry Pi Pico WH, latest versions of VScode, Thonny, Firmware, MicroPython with recommended VScode extensions installed (apart from Intellicode).

going to close this as it probably isn't a bug per-se. I've since experimented with the code, extending it to accept user input and pass that input into the function and the code executes as expected in VScode.