Skip to content

added examples folder and .py files #28

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

Merged
merged 4 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions examples/acceleration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import time
from adafruit_circuitplayground.express import cpx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add an import time and time.sleep(0.1) at least into this one so it is more reasonable to read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


while True:
x, y, z = cpx.acceleration
print(x, y, z)

time.sleep(0.1)
35 changes: 35 additions & 0 deletions examples/pixels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CircuitPython demo - NeoPixel

import time
from adafruit_circuitplayground.express import cpx


# The number of pixels in the strip
numpix = 10

def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if (pos < 0) or (pos > 255):
return (0, 0, 0)
if pos < 85:
return (int(pos * 3), int(255 - (pos*3)), 0)
elif pos < 170:
pos -= 85
return (int(255 - pos*3), 0, int(pos*3))
#else:
pos -= 170
return (0, int(pos*3), int(255 - pos*3))

def rainbow_cycle(wait):
for j in range(255):
for i in range(cpx.pixels.n):
idx = int((i * 256 / len(cpx.pixels)) + j)
cpx.pixels[i] = wheel(idx & 255)
cpx.pixels.show()
time.sleep(wait)

cpx.pixels.auto_write = False
cpx.pixels.brightness = 0.3
while True:
rainbow_cycle(0.001) # rainbowcycle with 1ms delay per step
5 changes: 5 additions & 0 deletions examples/shake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from adafruit_circuitplayground.express import cpx

while True:
if cpx.shake(shake_threshold=20):
print("Shake detected!")
22 changes: 22 additions & 0 deletions examples/tapdetect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from adafruit_circuitplayground.express import cpx

# Set to check for single-taps.
cpx.detect_taps = 1
tap_count = 0

# We're looking for 2 single-taps before moving on.
while tap_count < 2:
if cpx.tapped:
tap_count += 1
print("Reached 2 single-taps!")

# Now switch to checking for double-taps
tap_count = 0
cpx.detect_taps = 2

# We're looking for 2 double-taps before moving on.
while tap_count < 2:
if cpx.tapped:
tap_count += 1
print("Reached 2 double-taps!")
print("Done.")
7 changes: 7 additions & 0 deletions examples/tapdetectsimple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from adafruit_circuitplayground.express import cpx

cpx.detect_taps = 1

while True:
if cpx.tapped:
print("Single tap detected!")
9 changes: 9 additions & 0 deletions examples/tone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from adafruit_circuitplayground.express import cpx

while True:
if cpx.button_a:
cpx.start_tone(262)
elif cpx.button_b:
cpx.start_tone(294)
else:
cpx.stop_tone()
17 changes: 17 additions & 0 deletions examples/touched.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from adafruit_circuitplayground.express import cpx

while True:
if cpx.touch_A1:
print('Touched pad A1')
if cpx.touch_A2:
print('Touched pad A2')
if cpx.touch_A3:
print('Touched pad A3')
if cpx.touch_A4:
print('Touched pad A4')
if cpx.touch_A5:
print('Touched pad A5')
if cpx.touch_A6:
print('Touched pad A6')
if cpx.touch_A7:
print('Touched pad A7')