More code

master
Drew Bednar 4 years ago
parent f2f2326488
commit 80f7ef81d6

@ -77,4 +77,6 @@ def free(full=False):
P = '{0:.2f}%'.format(F/T*100) P = '{0:.2f}%'.format(F/T*100)
if not full: return P if not full: return P
else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P)) else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P))
``` ```
esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 460800 write_flash -z 0x1000 ~/Desktop/esp32spiram-idf3-20200902-v1.13.bin

@ -0,0 +1,17 @@
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.D13)
led.switch_to_output()
button_a = digitalio.DigitalInOut(board.D4)
button_a.switch_to_input(pull=digitalio.Pull.DOWN)
while True:
# if button_a.value:
# led.value = True
# else:
# led.value = False
led.value = not button_a.value
time.sleep(0.01)

@ -0,0 +1,98 @@
Welcome to CircuitPython!
#############################
Hello PyCon - we wanted to have a fun ~electronic~ item, that
does more than just a sticker! What you have in your hand is a special
edition Circuit Playground Express, brought to you by Adafruit and Digi-Key.
This hardware comes pre-loaded with CircuitPython! CircuitPython is Adafruit's
branch of MicroPython designed to simplify experimentation and education on
low-cost microcontrollers. It makes it easier than ever to get prototyping
by requiring no upfront desktop software downloads.
With CircuitPython you can write clean and simple Python 3 code to control
hardware instead of having to use complex low-level languages like C or C++
(what Arduino uses for programming). It's great for beginners and is powerful
for experts.
Enjoy PyCon 2019!
Thanks!
- the Adafruit and Digi-Key teams
#############################
Visit the Circuit Playground Express product page here for more info:
https://adafruit.com/product/3333
To get started with CircuitPython, which comes built into your Circuit
Playground Express, visit:
https://learn.adafruit.com/welcome-to-circuitpython
For a Circuit Playground Express Quickstart, examples, and content,
visit the PyCon 2019 GitHub repo:
https://github.com/adafruit/PyCon2019
#############################
The Circuit Playground Express has limited disk space so we have disabled Mac OS X indexing
which could take up that valuable space.
So *please* do not remove the empty .fseventsd/no_log, .metadata_never_index
or .Trashes files!
#############################
The pre-loaded demo shows off some of what your Circuit Playground Express
can do with CircuitPython:
* The NeoPixel ring on the CPX will do one of three LED animations based on your board's
unique ID. It will flash Digi-Key colors, Python colors or a red-comet rainbow swirl.
* The switch controls the little red LED. Move the switch left and right to turn the red
LED on and off.
* Press the buttons to play sounds. Button A and button B each play a different wav files.
* Change the TONE_PIANO variable to True at the top of the file to enable a tone piano on
the touch pads. Once enabled, you can touch the pads labeled A1-A7 to play a scale of tones.
For more details on how to use CircuitPython, visit
https://learn.adafruit.com/category/circuitpython
for all the tutorials we have!
#############################
Getting Start with Circuit Playground Express book excerpt!
Also included is a special preview edition of "Getting Started with Adafruit Circuit
Playground Express: The Multipurpose Learning and Development Board with Built-In LEDs,
Sensors, and Accelerometer" by Mike Barela. Make: Magazine gave PyCon, Adafruit &
Digi-Key special permission to include the CircuitPython chapter of the book for all
attendees to learn from and enjoy! Because CircuitPython allows devices to be USB
drives, the PDF is included right on the Circuit Playground Express! The complete book
is available on Adafruit and where programming books are sold:
https://www.adafruit.com/product/3944
#############################
Discount Code!
To help start you on your electronic journey, each PyCon attendee is receiving a Digi-Key
+ Adafruit Circuit Playground Express! You may decide that you want to explore more of
the wonderful world of electronics and Python on hardware, so we're also providing a
discount code to the Adafruit store. Use the code PYCONFRUIT and receive 10% off in stock
items in the Adafruit store!
https://www.adafruit.com
#############################
CircuitPython Quick Start:
Changing the code is as easy as editing code.py in your favorite text editor.
Our recommended editor is Mu, which is great for simple projects, and comes
with a built in REPL serial viewer! It is available for Mac, Windows & Linux
https://learn.adafruit.com/welcome-to-circuitpython/installing-mu-editor
After the file is saved, CircuitPython will automatically reload the latest
code.
Connecting to the serial port will give you access to sensor information,
better error messages and an interactive CircuitPython (known as the REPL).
On Windows we recommend Mu, Tera Term or PuTTY.
On Mac OSX and Linux, use Mu or 'screen' can be used from a terminal.

@ -0,0 +1 @@
Adafruit CircuitPython 4.0.0-beta.7 on 2019-04-13; Adafruit CircuitPlayground Express with samd21g18

@ -0,0 +1,105 @@
"""For a detailed guide on all the features of the Circuit Playground Express (cpx) library:
https://adafru.it/cp-made-easy-on-cpx"""
import time
import microcontroller
from adafruit_circuitplayground.express import cpx
# Set TONE_PIANO to True to enable a tone piano on the touch pads!
TONE_PIANO = True
LIGHTS = False
# Set this as a float from 0 to 1 to change the brightness. The decimal represents a percentage.
# So, 0.3 means 30% brightness!
cpx.pixels.brightness = 0.1
# Changes to NeoPixel state will not happen without explicitly calling show()
cpx.pixels.auto_write = True
# Startup behavior is based on your board's unique ID!
# uid returns a bytearray. The individual numbers are summed then modulo by 3.
# board_id = sum(microcontroller.cpu.uid) % 3
board_id = 1
def toggle_lights():
if cpx.switch:
LIGHTS = True
else:
LIGHTS = False
def color_wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition red - green - blue - back to red.
if pos < 0 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (int(255 - pos*3), int(pos*3), 0)
if pos < 170:
pos -= 85
return (0, int(255 - pos*3), int(pos*3))
pos -= 170
return (int(pos * 3), 0, int(255 - (pos*3)))
# Digi-Key colors: red and white!
digi_key_colors = ((255, 0, 0), (180, 180, 150))
# Python colors: blue and yellow!
python_colors = ((32, 64, 255), (255, 180, 20))
color_index = 0
pixel_number = 0
# time.monotonic() allows for non-blocking LED animations!
start = time.monotonic()
while True:
now = time.monotonic()
#if board_id == 0:
if cpx.switch and LIGHTS:
# Flash Digi-Key colors!
if now - start > 0.5:
color_index = (color_index + 1) % len(digi_key_colors)
cpx.pixels.fill(digi_key_colors[color_index])
cpx.pixels.show()
start = now
elif board_id == 1 and LIGHTS:
# Flash Python colors!
if now - start > 0.5:
color_index = (color_index + 1) % len(python_colors)
cpx.pixels.fill(python_colors[color_index])
cpx.pixels.show()
start = now
elif board_id == 2 and LIGHTS:
# Red-comet rainbow swirl!
pixel_number = (pixel_number + 1) % 10
for p in range(10):
color = color_wheel(25 * ((pixel_number + p) % 10))
cpx.pixels[p] = tuple([int(c * (10 - (pixel_number + p) % 10) / 10.0) for c in color])
cpx.pixels.show()
# If the switch is to the left, it returns True!
cpx.red_led = cpx.switch
# Press the buttons to play sounds!
if cpx.button_a:
cpx.play_file("low_fade.wav")
elif cpx.button_b:
cpx.play_file("low_fade.wav")
# Set TONE_PIANO to True above to enable a tone piano on the touch pads!
if TONE_PIANO:
if cpx.touch_A1:
#cpx.start_tone(262)
cpx.play_file("low_fade.wav")
elif cpx.touch_A2:
cpx.start_tone(294)
elif cpx.touch_A3:
cpx.start_tone(330)
elif cpx.touch_A4:
cpx.start_tone(349)
elif cpx.touch_A5:
cpx.start_tone(392)
elif cpx.touch_A6:
cpx.play_tone(440, 2.0)
elif cpx.touch_A7:
cpx.start_tone(494)
else:
cpx.stop_tone()

Binary file not shown.

Binary file not shown.

@ -1,24 +1,67 @@
from machine import Pin, PWM from machine import Pin, PWM
from time import sleep from time import sleep
from motor import MotorController
from neopixel import NeoPixel
print("Clank controller coming online") print("Clank controller coming online")
# pwm0 = PWM(Pin(0)) # create PWM object from a pin onboard_led = Pin(2, Pin.OUT)
# pwm0.freq() # get current frequency neo_pixel_pin = Pin(23, Pin.OUT)
# pwm0.freq(1000) # set frequency
# pwm0.duty() # get current duty cycle np = NeoPixel(neo_pixel_pin, 1)
# pwm0.duty(200) # set duty cycle
# pwm0.deinit() # turn off PWM on the pin # Motor A
pin_12 = Pin(12, Pin.OUT)
pin_14 = Pin(14, Pin.OUT)
pwm_13 = PWM(Pin(13), freq=1000, duty=0)
# Motor B
pin_25 = Pin(25, Pin.OUT)
pin_26 = Pin(26, Pin.OUT)
pwm_27 = PWM(Pin(27), freq=1000, duty=0)
front_motors = MotorController(pin_12, pin_14, pwm_13, False, pin_26, pin_25, pwm_27)
def blink_three_times(pin):
for i in range(0, 3):
pin.on()
sleep(.5)
pin.off()
sleep(.5)
pwm12 = PWM(Pin(12), freq=1000, duty=0)
pwm13 = PWM(Pin(13), freq=1000, duty=0)
while True: while True:
pwm12.duty(512) blink_three_times(onboard_led)
sleep(2) np[0] = (255, 255, 255)
pwm12.duty(0) np.write()
sleep(.3) # print("Setting the motors up!")
pwm13.duty(512) # onboard_led.on()
sleep(2) # front_motors.motor_a.forward = True
pwm13.duty(0) # front_motors.motor_b.forward = True
sleep(.3) # front_motors.motor_a.speed = 50
# front_motors.motor_b.speed = 50
# sleep(2)
# onboard_led.off()
# front_motors.motor_a.speed = 100
# front_motors.motor_b.speed = 100
# sleep(2)
# onboard_led.on()
# front_motors.motor_a.speed = 0
# front_motors.motor_b.speed = 0
# front_motors.motor_a.forward = False
# front_motors.motor_b.forward = False
# front_motors.motor_a.speed = 50
# front_motors.motor_b.speed = 50
# sleep(2)
# onboard_led.off()
# front_motors.motor_a.speed = 100
# front_motors.motor_b.speed = 100
# sleep(2)
# onboard_led.on()
# front_motors.motor_a.speed = 0
# front_motors.motor_b.speed = 0
# front_motors.motor_a.forward = True
# front_motors.motor_b.forward = True
# onboard_led.off()
# sleep(.3)

@ -0,0 +1,54 @@
class PWMMotor:
def __init__(self, dir_pin1, dir_pin2, enable_pin, flip_dir=False):
self._dir_pin1 = dir_pin1
self._dir_pin2 = dir_pin2
self._enable = enable_pin
self._flip_dir = flip_dir
self._direction = True
self._speed = 0.0
@property
def forward(self):
return self._direction
@forward.setter
def forward(self, direction):
check = not direction if self._flip_dir else direction
if check:
self._dir_pin1.on()
self._dir_pin2.off()
self._direction = True
else:
self._dir_pin1.off()
self._dir_pin2.on()
self._direction = False
@property
def speed(self):
return self._speed
@speed.setter
def speed(self, percentage):
f_percentage = float(percentage)
if f_percentage < 0 or f_percentage > 100:
raise ValueError('Speed must be a float or int from 0 to 100')
self._enable.duty(int(1023 / 100 * f_percentage))
self._speed = f_percentage
class ServoMotor(PWMMotor):
def __init__(self, dir_pin1, dir_pin2, enable_pin, flip_dir=False, sensor_pin_a=None, sensor_pin_b=None):
super().__init__(dir_pin1, dir_pin2, enable_pin, flip_dir=False)
sensor_pin_a = sensor_pin_a
sensor_pin_b = sensor_pin_b
class MotorController:
def __init__(self, dir_pin_a1=None, dir_pin_a2=None, enable_pin_a=None, flip_dir_a=False, dir_pin_b1=None,
dir_pin_b2=None,
enable_pin_b=None, flip_dir_b=False):
self.motor_a = PWMMotor(dir_pin_a1, dir_pin_a2, enable_pin_a, flip_dir_a)
self.motor_b = PWMMotor(dir_pin_b1, dir_pin_b2, enable_pin_b, flip_dir_b)

@ -0,0 +1,4 @@
from machine import UART
uart = UART(1, baudrate=9600, pins=("TX_PIN_HERE","RX_PIN_HERE"))
Loading…
Cancel
Save