Comments (3)
Hi @janickr ,
It works now! Thanks for your support :)
from kaspersmicrobit.
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.
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)
- Error importing kasper HOT 9
- bleak.exc.BleakError: Device with address D6:66:C1:A7:CF:0F was not found. HOT 6
- [bug] bleak.exc.BleakError: Characteristic (...) was not found! HOT 19
- Let me know if kaspersmicrobit works on macOS! HOT 5
- Python program freeze when using microbit.uart.send_string() HOT 5
- Cannot detect microbit HOT 31
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaspersmicrobit.