Skip to content

Commit 04f6bb1

Browse files
committed
serviceable bitbang version.
1 parent a09ec9e commit 04f6bb1

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

.travis.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Travis CI configuration for automated .mpy file generation.
2+
# Author: Tony DiCola
3+
# License: Public Domain
4+
# This configuration will work with Travis CI (travis-ci.org) to automacially
5+
# build .mpy files for MicroPython when a new tagged release is created. This
6+
# file is relatively generic and can be shared across multiple repositories by
7+
# following these steps:
8+
# 1. Copy this file into a .travis.yml file in the root of the repository.
9+
# 2. Change the deploy > file section below to list each of the .mpy files
10+
# that should be generated. The config will automatically look for
11+
# .py files with the same name as the source for generating the .mpy files.
12+
# Note that the .mpy extension should be lower case!
13+
# 3. Commit the .travis.yml file and push it to GitHub.
14+
# 4. Go to travis-ci.org and find the repository (it needs to be setup to access
15+
# your github account, and your github account needs access to write to the
16+
# repo). Flip the 'ON' switch on for Travis and the repo, see the Travis
17+
# docs for more details: https://docs.travis-ci.com/user/getting-started/
18+
# 5. Get a GitHub 'personal access token' which has at least 'public_repo' or
19+
# 'repo' scope: https://help.github.com/articles/creating-an-access-token-for-command-line-use/
20+
# Keep this token safe and secure! Anyone with the token will be able to
21+
# access and write to your GitHub repositories. Travis will use the token
22+
# to attach the .mpy files to the release.
23+
# 6. In the Travis CI settings for the repository that was enabled find the
24+
# environment variable editing page: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings
25+
# Add an environment variable named GITHUB_TOKEN and set it to the value
26+
# of the GitHub personal access token above. Keep 'Display value in build
27+
# log' flipped off.
28+
# 7. That's it! Tag a release and Travis should go to work to add .mpy files
29+
# to the release. It takes about a 2-3 minutes for a worker to spin up,
30+
# build mpy-cross, and add the binaries to the release.
31+
language: generic
32+
33+
sudo: true
34+
35+
deploy:
36+
provider: releases
37+
api_key: $GITHUB_TOKEN
38+
file:
39+
- "dotstar.mpy"
40+
skip_cleanup: true
41+
on:
42+
tags: true
43+
44+
before_install:
45+
- sudo apt-get -yqq update
46+
- sudo apt-get install -y build-essential git python python-pip
47+
- git clone https://github.com/adafruit/micropython.git
48+
- make -C micropython/mpy-cross
49+
- export PATH=$PATH:$PWD/micropython/mpy-cross/
50+
- sudo pip install shyaml
51+
52+
before_deploy:
53+
- shyaml get-values deploy.file < .travis.yml | sed 's/.mpy/.py/' | xargs -L1 mpy-cross

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2016 Adafruit Industries
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

dotstar.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# DotStar driver for CircuitPython
2+
# MIT license; Copyright (c) 2017 Ladyada & Damein George (original Neopixel object)
3+
4+
import digitalio
5+
import time
6+
7+
class DotStar:
8+
ORDER = (1, 0, 2, 3)
9+
def __init__(self, data, clock, n, bpp=3, brightness=1.0):
10+
self.dpin = digitalio.DigitalInOut(data)
11+
self.cpin = digitalio.DigitalInOut(clock)
12+
self.n = n
13+
self.bpp = bpp
14+
self.buf = bytearray(n * bpp)
15+
self.dpin.switch_to_output()
16+
self.cpin.switch_to_output()
17+
self.cpin.value = False
18+
self.brightness = brightness
19+
20+
def __enter__(self):
21+
return self
22+
23+
def __exit__(self, exception_type, exception_value, traceback):
24+
self.dpin.deinit()
25+
self.cpin.deinit()
26+
27+
def __setitem__(self, index, val):
28+
offset = index * self.bpp
29+
for i in range(self.bpp):
30+
self.buf[offset + self.ORDER[i]] = val[i]
31+
32+
def __getitem__(self, index):
33+
offset = index * self.bpp
34+
return tuple(self.buf[offset + self.ORDER[i]]
35+
for i in range(self.bpp))
36+
37+
def __len__(self):
38+
return self.n
39+
40+
def set_brightness(self, range):
41+
if (range > 1.0):
42+
self.brightness = 1.0
43+
elif (range < 0):
44+
self.brightness = 0.0
45+
else:
46+
self.brightness = range
47+
48+
def fill(self, color):
49+
for i in range(self.n):
50+
self[i] = color
51+
52+
def ds_writebytes(self, bytes):
53+
for b in bytes:
54+
for i in range(8):
55+
self.cpin.value = True
56+
self.dpin.value = (b & 0x80)
57+
self.cpin.value = False
58+
b = b << 1
59+
60+
def write(self):
61+
# Tell strip we're ready with many 0x00's
62+
self.ds_writebytes([0x00, 0x00, 0x00, 0x00])
63+
for i in range(self.n):
64+
# each pixel starts with 0xFF, then red/green/blue
65+
pixel = [0xFF, 0, 0, 0]
66+
# scale each pixel by the brightness
67+
for x in range(3):
68+
pixel[x+1] = int(self.buf[i * self.bpp + x] * self.brightness)
69+
# write this pixel
70+
self.ds_writebytes(pixel)
71+
# Tell strip we're done with many 0xFF's
72+
self.ds_writebytes([0xFF, 0xFF, 0xFF, 0xFF])
73+
self.cpin.value = False

0 commit comments

Comments
 (0)