Git Product home page Git Product logo

Comments (3)

idef1x avatar idef1x commented on August 20, 2024 2

Hi @janickr ,
It works now! Thanks for your support :)

from kaspersmicrobit.

janickr avatar janickr commented on August 20, 2024

Hi @idef1x, no worries I'm happy to help

Writing a to a single pin is supported: you can supply a list containing only one pin value, like this:

# wrapping the PinValue in [ ] creates a list
microbit.io_pin.write_data([PinValue(Pin.P1, 1)])

The bluetooth io pin service in the microbit bluetooth profile defines the result of the read operation to return the values for all input pins. Kaspersmicrobit cannot change that.

If you define a function which looks for the pin in the list and returns the value if it exists:

def pin_value(pin, values):
    return next((v.value for v in values if v.pin == pin), None)

Then you can select the value of a single pin:

value_of_p1 = pin_value(Pin.P1, your_microbit.io_pin.read_data())

An alternative could be a function to create a dict from the list of values:

from collections import defaultdict

def to_dict(values):
    return defaultdict(lambda:None, {p.pin: p.value for p in values})

this can help you access values from different pins:

pin_values = to_dict(your_microbit.io_pin.read_data())
value_of_p1 = pin_values[Pin.P1] 
value_of_p5 = pin_values[Pin.P5] 

Maybe I'll also include a function like this in a next release of Kaspersmicrobit .

from kaspersmicrobit.

idef1x avatar idef1x commented on August 20, 2024

Hi @janickr ,

Thanks for your swift response! Will try it out after the weekend as it's to sunny atm here in the Netherlands ;-)
Will let you know if I succeed :-)

from kaspersmicrobit.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.