bbc microbit - Are there event callbacks in BBC MicroPython? -




i trying translate following javascript micropython micro:bit. code example 3 inventor's kit translated block javascript.

let light_state = 0 # how do bit? input.onpinpressed(touchpin.p0, () => {     if (light_state == 0) {         light_state = 1     } else {         light_state = 0     } }) basic.forever(() => {     if (light_state == 1) {         pins.analogwritepin(analogpin.p2, pins.analogreadpin(analogpin.p1))     } else {         pins.digitalwritepin(digitalpin.p2, 0)     } }) 

i can't figure out how input.onpinpressed callback event or lambda. best can come poll pin0 repeatedly.

from microbit import *  light_on = false while true:     if pin0.is_touched():         light_on = not light_on                 if light_on:             aval = pin1.read_analog()             pin2.write_analog(aval)         else:             pin2.write_digital(0) 

i have seen callbacks on switches in micropython documentation haven't come across event callbacks micro:bit pins. there example code feature, if undocumented?

edit: made corrections code - previous micropython translation caused led flicker continuously.

the reply micro:bit forum is

the micropython micro:bit api designed teaching , use school children, , decided not include callbacks in api because can lead complicated bugs. instead need poll pin.





wiki

Comments

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

Asterisk AGI Python Script to Dialplan does not work -