Skip to content

Commit b3b3d19

Browse files
authored
Merge branch 'master' into master
2 parents d37f0ac + 6a68fba commit b3b3d19

File tree

6 files changed

+474
-4
lines changed

6 files changed

+474
-4
lines changed

Circuit_Playground_Bluefruit_NeoPixel_Controller/NeoPixel_Animator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@
8383
if isinstance(packet, ColorPacket): # If the packet is color packet...
8484
if mode == 0: # And mode is 0...
8585
animations.color = packet.color # Update the animation to the color.
86-
print("Color:", packet.color)
86+
# Uncomment below to see the color tuple printed to the serial console.
87+
# print("Color:", packet.color)
8788
animation_color = packet.color # Keep track of the current color...
8889
elif mode == 1: # Because if mode is 1...
8990
animations.color = animation_color # Freeze the animation color.
90-
print("Color:", animation_color)
91+
# Uncomment below to see the color tuple printed to the serial console.
92+
# print("Color:", animation_color)
9193
elif isinstance(packet, ButtonPacket): # If the packet is a button packet...
9294
# Check to see if it's BUTTON_1 (which is being sent by the slide switch)
9395
if packet.button == ButtonPacket.BUTTON_1:

ItsyBitsy_Infinity_Cube/code.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
NeoPixel Animator code for ItsyBitsy nRF52840 NeoPixel Animation and Color Remote Control.
3+
"""
4+
5+
import board
6+
import neopixel
7+
from adafruit_led_animation.animation import Comet, Sparkle, AnimationGroup,\
8+
AnimationSequence
9+
import adafruit_led_animation.color as color
10+
11+
from adafruit_ble import BLERadio
12+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
13+
from adafruit_ble.services.nordic import UARTService
14+
15+
from adafruit_bluefruit_connect.packet import Packet
16+
from adafruit_bluefruit_connect.color_packet import ColorPacket
17+
from adafruit_bluefruit_connect.button_packet import ButtonPacket
18+
19+
# The number of NeoPixels in the externally attached strip
20+
# If using two strips connected to the same pin, count only one strip for this number!
21+
STRIP_PIXEL_NUMBER = 43
22+
23+
# Setup for comet animation
24+
COMET_SPEED = 0.05 # Lower numbers increase the animation speed
25+
STRIP_COMET_TAIL_LENGTH = 10 # The length of the comet on the NeoPixel strip
26+
STRIP_COMET_BOUNCE = False # Set to False to stop comet from "bouncing" on NeoPixel strip
27+
28+
# Setup for sparkle animation
29+
SPARKLE_SPEED = 0.1 # Lower numbers increase the animation speed
30+
31+
# Create the NeoPixel strip
32+
strip_pixels = neopixel.NeoPixel(board.D5, STRIP_PIXEL_NUMBER, auto_write=False)
33+
34+
# Setup BLE connection
35+
ble = BLERadio()
36+
uart = UARTService()
37+
advertisement = ProvideServicesAdvertisement(uart)
38+
39+
# Setup animations
40+
animations = AnimationSequence(
41+
AnimationGroup(
42+
Sparkle(strip_pixels, SPARKLE_SPEED, color.TEAL)
43+
),
44+
AnimationGroup(
45+
Comet(strip_pixels, COMET_SPEED, color.TEAL, tail_length=STRIP_COMET_TAIL_LENGTH,
46+
bounce=STRIP_COMET_BOUNCE)
47+
),
48+
)
49+
50+
animation_color = None
51+
mode = 0
52+
blanked = False
53+
54+
while True:
55+
ble.start_advertising(advertisement) # Start advertising.
56+
was_connected = False
57+
while not was_connected or ble.connected:
58+
if not blanked: # If LED-off signal is not being sent...
59+
animations.animate() # Run the animations.
60+
if ble.connected: # If BLE is connected...
61+
was_connected = True
62+
if uart.in_waiting: # Check to see if any data is available from the Remote Control.
63+
try:
64+
packet = Packet.from_stream(uart) # Create the packet object.
65+
except ValueError:
66+
continue
67+
if isinstance(packet, ColorPacket): # If the packet is color packet...
68+
if mode == 0: # And mode is 0...
69+
animations.color = packet.color # Update the animation to the color.
70+
print("Color:", packet.color)
71+
animation_color = packet.color # Keep track of the current color...
72+
elif mode == 1: # Because if mode is 1...
73+
animations.color = animation_color # Freeze the animation color.
74+
print("Color:", animation_color)
75+
elif isinstance(packet, ButtonPacket): # If the packet is a button packet...
76+
if packet.pressed: # If the buttons on the Remote Control are pressed...
77+
if packet.button == ButtonPacket.LEFT: # If button A is pressed...
78+
print("A pressed: animation mode changed.")
79+
animations.next() # Change to the next animation.
80+
elif packet.button == ButtonPacket.RIGHT: # If button B is pressed...
81+
mode += 1 # Increase the mode by 1.
82+
if mode == 1: # If mode is 1, print the following:
83+
print("B pressed: color frozen!")
84+
if mode > 1: # If mode is > 1...
85+
mode = 0 # Set mode to 0, and print the following:
86+
print("B pressed: color changing!")

LSM303/lsm303agr_combined.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import board
33
import busio
44
import adafruit_lsm303_accel
5-
import adafruit_lsm303agr_mag
5+
import adafruit_lis2mdl
66

77
i2c = busio.I2C(board.SCL, board.SDA)
8-
mag = adafruit_lsm303agr_mag.LSM303AGR_Mag(i2c)
8+
mag = adafruit_lis2mdl.LIS2MDL(i2c)
99
accel = adafruit_lsm303_accel.LSM303_Accel(i2c)
1010

1111
while True:

M4_Eyes/user_pir.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#if 0 // Change to 1 to enable this code (must enable ONE user*.cpp only!)
2+
3+
// PIR motion sensor on pin 3 makes eyes open when motion is detected.
4+
5+
#include "globals.h"
6+
7+
#define PIR_PIN 3 // PIR sensor on D3 connector (between MIC & BAT)
8+
9+
static uint8_t priorState;
10+
11+
void user_setup(void) {
12+
pinMode(PIR_PIN, INPUT);
13+
priorState = digitalRead(PIR_PIN);
14+
for(uint8_t e=0; e<NUM_EYES; e++) {
15+
// Init to DEBLINK with an impossibly large duration to hold eyes shut.
16+
eye[e].blink.state = DEBLINK;
17+
eye[e].blink.duration = 0x7FFFFFFF;
18+
eye[e].blink.startTime = micros();
19+
}
20+
}
21+
22+
void user_loop(void) {
23+
uint8_t e, newState = digitalRead(PIR_PIN);
24+
if(newState != priorState) {
25+
if(newState) {
26+
// Initial motion sensed
27+
for(e=0; e<NUM_EYES; e++) { // For each eye...
28+
eye[e].blink.state = DEBLINK; // Opening...
29+
eye[e].blink.duration = 500000; // Slowly, about 1/2 sec
30+
eye[e].blink.startTime = micros(); // Starting now
31+
}
32+
} else {
33+
// PIR timeout; "end" of motion
34+
for(e=0; e<NUM_EYES; e++) { // For each eye...
35+
if(eye[e].blink.state != ENBLINK) { // If not already blinking...
36+
eye[e].blink.state = ENBLINK; // Start closing...
37+
eye[e].blink.duration = 1500000; // Even slower, about 1.5 sec
38+
eye[e].blink.startTime = micros(); // Starting now
39+
}
40+
}
41+
}
42+
priorState = newState;
43+
} else if(!newState) {
44+
// No change in state. If currently no motion active,
45+
// force eyes into closed position at every opportunity.
46+
for(e=0; e<NUM_EYES; e++) { // For each eye...
47+
if(eye[e].blink.state != ENBLINK) { // If not currently blinking...
48+
// Set to DEBLINK with an impossibly large duration -- eyes will
49+
// hold shut until motion event above resets start & duration.
50+
eye[e].blink.state = DEBLINK;
51+
eye[e].blink.duration = 0x7FFFFFFF;
52+
eye[e].blink.startTime = micros();
53+
}
54+
}
55+
}
56+
}
57+
58+
#endif // 0

0 commit comments

Comments
 (0)