Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mryslab/pymata-cpx
A Python API Interface For the Adafruit Circuit Playground Express
https://github.com/mryslab/pymata-cpx
c-plus-plus python3
Last synced: 18 days ago
JSON representation
A Python API Interface For the Adafruit Circuit Playground Express
- Host: GitHub
- URL: https://github.com/mryslab/pymata-cpx
- Owner: MrYsLab
- License: agpl-3.0
- Created: 2019-11-01T12:59:57.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-30T23:25:52.000Z (almost 5 years ago)
- Last Synced: 2024-10-15T01:28:53.072Z (22 days ago)
- Topics: c-plus-plus, python3
- Language: C++
- Homepage:
- Size: 2.08 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
![logo](https://github.com/MrYsLab/pymata-cpx/blob/master/docs/images/cpx.jpg)
## Control A Circuit Playground Express From Your PC With An Easy To Use Python 3 API
View the Installation and Usage Guide [Here.](https://mryslab.github.io/pymata-cpx/)
It supports the following CPX devices:
* The Buttons and Slide Switch.
* The D13 Board LED.
* The 10 onboard neo-pixels.
* Tone generation using the onboard speaker.
* The accelerometer, including tap sensing.
* The temperature sensor.
* The light sensor.
* The sound sensor.
* Touchpad sensors.An example to animate the neopixels and to start and stop the animation
by simply tapping the Playground Express:```python
import random
import timefrom pymata_cpx.pymata_cpx import PyMataCpx
class TheTapper():
"""
Illuminate the neopixels in a counter-clockwise fashion with randomly generated colors.
When you tap the playground express, the neopixels will stop changing and the
program pauses. Tap again and the neopixels will start again.
"""
def __init__(self):
# create an instance of the API
self.p = PyMataCpx()print('Tap the playground express to stop the neopixels from moving.')
print('Tap again, to start them up')
print('The tap state will be printed to the console')# Start monitoring for tap events and
# send event notifications to the "tapped" callback method.
self.p.cpx_tap_start(self.tapped)
# flag to start and stop the light show
self.go = Truewhile True:
try:
# run the light show
for neopixel in range(0, 10):
# check the go flag
if self.go:
self.p.cpx_pixels_clear()
self.p.cpx_pixels_show()
r = random.randint(0, 254)
g = random.randint(0, 254)
b = random.randint(0, 254)
self.p.cpx_pixel_set(neopixel, r, g, b)
self.p.cpx_pixels_show()
time.sleep(.2)
else:
self.p.cpx_pixels_clear()
self.p.cpx_pixels_show()
time.sleep(.001)
except KeyboardInterrupt:
# If you press control-C, cleanly exit
self.p.cpx_pixels_clear()
self.p.cpx_pixels_show()
self.p.cpx_close_and_exit()def tapped(self, data):
"""
:param data: data[0] = data type (analog = 2, digital =32)
data[1] = pin for device 27
data[2] = tap data - list of booleans.
First value for 1 tap
Second value for 2 taps
"""
# for any taps, toggle the go flag
# print out the current go state
if data[2] != [False, False]:
self.go = not self.go
print(self.go)# start the program
TheTapper()```
This project was developed with
[Pycharm](https://www.jetbrains.com/pycharm/?from=pymata-cpx)
![logo](https://github.com/MrYsLab/python_banyan/blob/master/images/icon_PyCharm.png)