Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added two suggestions #13

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 116 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ But it's probably easiest to do a Cmd-F/Ctrl-F find on keyword of idea you want.
* [Output a "Analog" value on a PWM pin](#output-a-analog-value-on-a-pwm-pin)
* [Control Neopixel / WS2812 LEDs](#control-neopixel--ws2812-leds)
* [Control a servo, with animation list](#control-a-servo-with-animation-list)

* [Neopixels / Dotstars](#neopixels--dotstars)
* [Moving rainbow on built-in board.NEOPIXEL](#moving-rainbow-on-built-in-boardneopixel)
* [Make moving rainbow gradient across LED strip](#make-moving-rainbow-gradient-across-led-strip)
* [Fade all LEDs by amount for chase effects](#fade-all-leds-by-amount-for-chase-effects)
* [Dictionary for HTML Color Names](#dictionary-for-html-color-names)

* [Audio](#audio)
* [Audio out using PWM](#audio-out-using-pwm)
* [Audio out using DAC](#audio-out-using-dac)
Expand Down Expand Up @@ -79,6 +82,7 @@ But it's probably easiest to do a Cmd-F/Ctrl-F find on keyword of idea you want.
* [I2C](#i2c)
* [Scan I2C bus for devices](#scan-i2c-bus-for-devices)
* [Speed up I2C bus](#speed-up-i2c-bus)
* [Using Matrix Keypad with I2C Port Expander](#using-i2c-port-expander-with-matrix-keypad)
* [Timing](#timing)
* [Measure how long something takes](#measure-how-long-something-takes)
* [More accurate timing with ticks_ms(), like Arduino millis()](#more-accurate-timing-with-ticks_ms-like-arduino-millis)
Expand Down Expand Up @@ -243,8 +247,6 @@ while True:
if button.released:
print("button", button.key_number, "released!")
```


## Outputs

### Output HIGH / LOW on a pin (like an LED)
Expand Down Expand Up @@ -405,7 +407,88 @@ while True:
leds.show() # only write to LEDs after updating them all
time.sleep(0.05)
```

### Dictionary for HTML Color Names
Then you can call CRGB ['ColorName'] in same manner that you call CRGB::ColorName in Arduino and FastLed

```py
CRGB = {
'MistyRose': (1.0, 0.894118, 0.882353), 'Red': (1.0, 0.0, 0.0),
'FairyLight': (1.0, 0.894118, 0.176471),'LemonChiffon': (1.0, 0.980392, 0.803922),
'SlateGrey': (0.439216, 0.501961, 0.564706),'FairyLightNCC': (1.0, 0.615686, 0.164706),
'Lavender': (0.901961, 0.901961, 0.980392), 'Gainsboro': (0.862745, 0.862745, 0.862745),
'PowderBlue': (0.690196, 0.878431, 0.901961), 'Aqua': (0.0, 1.0, 1.0),
'Crimson': (0.862745, 0.0784314, 0.235294), 'PaleVioletRed': (0.858824, 0.439216, 0.576471),
'SandyBrown': (0.956863, 0.643137, 0.376471), 'DeepSkyBlue': (0.0, 0.74902, 1.0),
'BurlyWood': (0.870588, 0.721569, 0.529412), 'DarkBlue': (0.0, 0.0, 0.545098),
'DarkGrey': (0.662745, 0.662745, 0.662745), 'LightPink': (1.0, 0.713725, 0.756863),
'DarkRed': (0.545098, 0.0, 0.0), 'MidnightBlue': (0.0980392, 0.0980392, 0.439216),
'DimGrey': (0.411765, 0.411765, 0.411765), 'Grey': (0.501961, 0.501961, 0.501961),
'Orange': (1.0, 0.647059, 0.0), 'FloralWhite': (1.0, 0.980392, 0.941176),
'AliceBlue': (0.941176, 0.972549, 1.0), 'Magenta': (1.0, 0.0, 1.0),
'MediumSpringGreen': (0.0, 0.980392, 0.603921), 'PaleTurquoise': (0.686275, 0.933333, 0.933333),
'Turquoise': (0.25098, 0.878431, 0.815686), 'Orchid': (0.854902, 0.439216, 0.839215),
'BlueViolet': (0.541176, 0.168627, 0.886274), 'Coral': (1.0, 0.498039, 0.313725),
'PeachPuff': (1.0, 0.854902, 0.72549), 'Peru': (0.803922, 0.521569, 0.247059),
'MediumOrchid': (0.729412, 0.333333, 0.827451), 'DarkOliveGreen': (0.333333, 0.419608, 0.184314),
'Sienna': (0.627451, 0.321569, 0.176471), 'Honeydew': (0.941176, 1.0, 0.941176),
'ForestGreen': (0.133333, 0.545098, 0.133333), 'DimGray': (0.411765, 0.411765, 0.411765),
'Gray': (0.501961, 0.501961, 0.501961), 'HotPink': (1.0, 0.411765, 0.705882),
'MediumSlateBlue': (0.482353, 0.407843, 0.933333), 'Brown': (0.647059, 0.164706, 0.164706),
'FireBrick': (0.698039, 0.133333, 0.133333), 'GhostWhite': (0.972549, 0.972549, 1.0),
'Gold': (1.0, 0.843137, 0.0), 'LightBlue': (0.678431, 0.847059, 0.901961),
'DarkSlateBlue': (0.282353, 0.239216, 0.545098), 'LightGrey': (0.827451, 0.827451, 0.827451),
'LawnGreen': (0.486274, 0.988235, 0.0), 'Lime': (0.0, 1.0, 0.0),
'DarkMagenta': (0.545098, 0.0, 0.545098), 'LimeGreen': (0.196078, 0.803922, 0.196078),
'MediumVioletRed': (0.780392, 0.0823529, 0.521569), 'Moccasin': (1.0, 0.894118, 0.709804),
'OldLace': (0.992157, 0.960784, 0.901961), 'Chocolate': (0.823529, 0.411765, 0.117647),
'PaleGoldenrod': (0.933333, 0.909804, 0.666667), 'Bisque': (1.0, 0.894118, 0.768627),
'Chartreuse': (0.498039, 1.0, 0.0), 'DarkViolet': (0.580392, 0.0, 0.827451),
'Olive': (0.501961, 0.501961, 0.0), 'PaleGreen': (0.596078, 0.984314, 0.596078),
'PapayaWhip': (1.0, 0.937255, 0.835294), 'Pink': (1.0, 0.752941, 0.796078),
'MintCream': (0.960784, 1.0, 0.980392), 'DodgerBlue': (0.117647, 0.564706, 1.0),
'Khaki': (0.941176, 0.901961, 0.54902), 'Aquamarine': (0.498039, 1.0, 0.831372),
'DarkTurquoise': (0.0, 0.807843, 0.819608), 'Green': (0.0, 0.501961, 0.0),
'LightSlateGrey': (0.466667, 0.533333, 0.6), 'Purple': (0.501961, 0.0, 0.501961),
'DarkGreen': (0.0, 0.392157, 0.0), 'DarkCyan': (0.0, 0.545098, 0.545098),
'DarkSalmon': (0.913725, 0.588235, 0.478431), 'LightGoldenrodYellow': (0.980392, 0.980392, 0.823529),
'LavenderBlush': (1.0, 0.941176, 0.960784), 'Navy': (0.0, 0.0, 0.501961),
'Cornsilk': (1.0, 0.972549, 0.862745), 'LightSalmon': (1.0, 0.627451, 0.478431),
'IndianRed': (0.803922, 0.360784, 0.360784), 'BlanchedAlmond': (1.0, 0.921569, 0.803922),
'CadetBlue': (0.372549, 0.619608, 0.627451), 'DeepPink': (1.0, 0.0784314, 0.576471),
'MediumSeaGreen': (0.235294, 0.701961, 0.443137), 'Plaid': (0.8, 0.333333, 0.2),
'Cyan': (0.0, 1.0, 1.0), 'AntiqueWhite': (0.980392, 0.921569, 0.843137),
'Blue': (0.0, 0.0, 1.0), 'LightSlateGray': (0.466667, 0.533333, 0.6),
'RosyBrown': (0.737255, 0.560784, 0.560784), 'RoyalBlue': (0.254902, 0.411765, 0.882353),
'SeaGreen': (0.180392, 0.545098, 0.341176), 'LightSeaGreen': (0.12549, 0.698039, 0.666667),
'MediumAquamarine': (0.4, 0.803922, 0.666667), 'DarkOrchid': (0.6, 0.196078, 0.8),
'GreenYellow': (0.678431, 1.0, 0.184314), 'DarkSlateGray': (0.184314, 0.309804, 0.309804),
'Azure': (0.941176, 1.0, 1.0), 'Fuchsia': (1.0, 0.0, 1.0),
'Indigo': (0.294118, 0.0, 0.509804), 'Ivory': (1.0, 1.0, 0.941176),
'Beige': (0.960784, 0.960784, 0.862745), 'DarkOrange': (1.0, 0.54902, 0.0),
'LightCoral': (0.941176, 0.501961, 0.501961), 'Linen': (0.980392, 0.941176, 0.901961),
'MediumBlue': (0.0, 0.0, 0.803922), 'LightCyan': (0.878431, 1.0, 1.0),
'OliveDrab': (0.419608, 0.556863, 0.137255), 'SaddleBrown': (0.545098, 0.270588, 0.0745098),
'Salmon': (0.980392, 0.501961, 0.447059), 'Seashell': (1.0, 0.960784, 0.933333),
'Silver': (0.752941, 0.752941, 0.752941), 'SkyBlue': (0.529412, 0.807843, 0.921569),
'Maroon': (0.501961, 0.0, 0.0), 'SlateBlue': (0.415686, 0.352941, 0.803922),
'Goldenrod': (0.854902, 0.647059, 0.12549), 'Snow': (1.0, 0.980392, 0.980392),
'DarkKhaki': (0.741176, 0.717647, 0.419608), 'SpringGreen': (0.0, 1.0, 0.498039),
'SteelBlue': (0.27451, 0.509804, 0.705882), 'Tan': (0.823529, 0.705882, 0.54902),
'Teal': (0.0, 0.501961, 0.501961), 'Thistle': (0.847059, 0.74902, 0.847059),
'DarkSlateGrey': (0.184314, 0.309804, 0.309804), 'LightGreen': (0.564706, 0.933333, 0.564706),
'LightYellow': (1.0, 1.0, 0.878431), 'Black': (0.0, 0.0, 0.0),
'MediumTurquoise': (0.282353, 0.819608, 0.8), 'LightSkyBlue': (0.529412, 0.807843, 0.980392),
'NavajoWhite': (1.0, 0.870588, 0.678431), 'OrangeRed': (1.0, 0.270588, 0.0),
'Plum': (0.866667, 0.627451, 0.866667), 'SlateGray': (0.439216, 0.501961, 0.564706),
'Tomato': (1.0, 0.388235, 0.278431), 'Violet': (0.933333, 0.509804, 0.933333),
'DarkGoldenrod': (0.721569, 0.52549, 0.0431373), 'Wheat': (0.960784, 0.870588, 0.701961),
'White': (1.0, 1.0, 1.0), 'Amethyst': (0.6, 0.4, 0.8),
'CornflowerBlue': (0.392157, 0.584314, 0.929412), 'LightSteelBlue': (0.690196, 0.768627, 0.870588),
'WhiteSmoke': (0.960784, 0.960784, 0.960784), 'Yellow': (1.0, 1.0, 0.0),
'YellowGreen': (0.603921, 0.803922, 0.196078), 'DarkGray': (0.662745, 0.662745, 0.662745),
'DarkSeaGreen': (0.560784, 0.737255, 0.560784), 'MediumPurple': (0.576471, 0.439216, 0.858824)
}
```
## Audio

In CircuitPython, there are three different techniques to output audio:
Expand Down Expand Up @@ -1178,6 +1261,36 @@ i2c = busio.I2C( board.SCL, board.SDA, frequency=200_000)
# then do something with 'i2c' object as before, like:
oled = adafruit_ssd1306.SSD1306_I2C(width=128, height=32, i2c=i2c)
```
### Using I2C Port Expander With Matrix Keypad
```py
import adafruit_matrixkeypad
import adafruit_pcf8574
from digitalio import DigitalInOut
import board
import time
# Using default i2c with board.SDA e board.SCL
i2c = board.I2C()
pcf = adafruit_pcf8574.PCF8574(i2c, 0x20)

# Classic 3x4 matrix keypad
# I directly soldered the pcf8574 module on the keypad
# with pinout C2 R1 C1 R4 C3 R3 R2
cols = [pcf.get_pin(4), pcf.get_pin(6), pcf.get_pin(2)]
rows = [pcf.get_pin(5), pcf.get_pin(0), pcf.get_pin(1), pcf.get_pin(3)]

keys = ((1, 2, 3),
(4, 5, 6),
(7, 8, 9),
('*', 0, '#'))

keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)

while True:
keys = keypad.pressed_keys
if keys:
print("Pressed: ", keys)
time.sleep(0.1)
```

## Timing

Expand Down