Fixes line ending issues
This commit is contained in:
parent
dc1aac7767
commit
355447daff
6 changed files with 193 additions and 194 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
|
@ -1 +0,0 @@
|
||||||
*.py text eol=lf
|
|
||||||
|
|
@ -1,46 +1,46 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import pulseio
|
import pulseio
|
||||||
from digitalio import DigitalInOut, Direction
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
# PWM (fading) LEDs are connected on D0 (PWM not avail on D1)
|
# PWM (fading) LEDs are connected on D0 (PWM not avail on D1)
|
||||||
pwm_leds = board.D0
|
pwm_leds = board.D0
|
||||||
pwm = pulseio.PWMOut(pwm_leds, frequency=1000, duty_cycle=0)
|
pwm = pulseio.PWMOut(pwm_leds, frequency=1000, duty_cycle=0)
|
||||||
|
|
||||||
# digital LEDs connected on D2
|
# digital LEDs connected on D2
|
||||||
digital_leds = DigitalInOut(board.D2)
|
digital_leds = DigitalInOut(board.D2)
|
||||||
digital_leds.direction = Direction.OUTPUT
|
digital_leds.direction = Direction.OUTPUT
|
||||||
brightness = 0 # how bright the LED is
|
brightness = 0 # how bright the LED is
|
||||||
fade_amount = 1285 # 2% steping of 2^16
|
fade_amount = 1285 # 2% steping of 2^16
|
||||||
counter = 0 # counter to keep track of cycles
|
counter = 0 # counter to keep track of cycles
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
# And send to LED as PWM level
|
# And send to LED as PWM level
|
||||||
pwm.duty_cycle = brightness
|
pwm.duty_cycle = brightness
|
||||||
|
|
||||||
# change the brightness for next time through the loop:
|
# change the brightness for next time through the loop:
|
||||||
brightness = brightness + fade_amount
|
brightness = brightness + fade_amount
|
||||||
|
|
||||||
print(brightness)
|
print(brightness)
|
||||||
|
|
||||||
# reverse the direction of the fading at the ends of the fade:
|
# reverse the direction of the fading at the ends of the fade:
|
||||||
if brightness <= 0:
|
if brightness <= 0:
|
||||||
fade_amount = -fade_amount
|
fade_amount = -fade_amount
|
||||||
counter += 1
|
counter += 1
|
||||||
elif brightness >= 65535:
|
elif brightness >= 65535:
|
||||||
fade_amount = -fade_amount
|
fade_amount = -fade_amount
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
# wait for 15 ms to see the dimming effect
|
# wait for 15 ms to see the dimming effect
|
||||||
time.sleep(.015)
|
time.sleep(.015)
|
||||||
|
|
||||||
# turns on the other LEDs every four times through the fade by
|
# turns on the other LEDs every four times through the fade by
|
||||||
# checking the modulo of the counter.
|
# checking the modulo of the counter.
|
||||||
# the modulo function gives you the remainder of
|
# the modulo function gives you the remainder of
|
||||||
# the division of two numbers:
|
# the division of two numbers:
|
||||||
if counter % 4 == 0:
|
if counter % 4 == 0:
|
||||||
digital_leds.value = True
|
digital_leds.value = True
|
||||||
else:
|
else:
|
||||||
digital_leds.value = False
|
digital_leds.value = False
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,52 @@
|
||||||
# Gemma M0 version of TVBgone!
|
# Gemma M0 version of TVBgone!
|
||||||
import array
|
import array
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import adafruit_dotstar
|
import adafruit_dotstar
|
||||||
import board
|
import board
|
||||||
import pulseio
|
import pulseio
|
||||||
from digitalio import DigitalInOut, Direction
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
pixel = adafruit_dotstar.DotStar(
|
pixel = adafruit_dotstar.DotStar(
|
||||||
board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
|
board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
|
||||||
pixel.fill((0, 0, 0))
|
pixel.fill((0, 0, 0))
|
||||||
|
|
||||||
# Button to see output debug
|
# Button to see output debug
|
||||||
led = DigitalInOut(board.D13)
|
led = DigitalInOut(board.D13)
|
||||||
led.direction = Direction.OUTPUT
|
led.direction = Direction.OUTPUT
|
||||||
|
|
||||||
pwm = pulseio.PWMOut(board.A1, frequency=38000,
|
pwm = pulseio.PWMOut(board.A1, frequency=38000,
|
||||||
duty_cycle=2 ** 15, variable_frequency=True)
|
duty_cycle=2 ** 15, variable_frequency=True)
|
||||||
pulse = pulseio.PulseOut(pwm)
|
pulse = pulseio.PulseOut(pwm)
|
||||||
|
|
||||||
time.sleep(0.5) # Give a half second before starting
|
time.sleep(0.5) # Give a half second before starting
|
||||||
|
|
||||||
# gooooo!
|
# gooooo!
|
||||||
f = open("/codes.txt", "r")
|
f = open("/codes.txt", "r")
|
||||||
for line in f:
|
for line in f:
|
||||||
code = eval(line)
|
code = eval(line)
|
||||||
print(code)
|
print(code)
|
||||||
pwm.frequency = code['freq']
|
pwm.frequency = code['freq']
|
||||||
led.value = True
|
led.value = True
|
||||||
# If this is a repeating code, extract details
|
# If this is a repeating code, extract details
|
||||||
try:
|
try:
|
||||||
repeat = code['repeat']
|
repeat = code['repeat']
|
||||||
delay = code['repeat_delay']
|
delay = code['repeat_delay']
|
||||||
except KeyError: # by default, repeat once only!
|
except KeyError: # by default, repeat once only!
|
||||||
repeat = 1
|
repeat = 1
|
||||||
delay = 0
|
delay = 0
|
||||||
# The table holds the on/off pairs
|
# The table holds the on/off pairs
|
||||||
table = code['table']
|
table = code['table']
|
||||||
pulses = [] # store the pulses here
|
pulses = [] # store the pulses here
|
||||||
# Read through each indexed element
|
# Read through each indexed element
|
||||||
for i in code['index']:
|
for i in code['index']:
|
||||||
pulses += table[i] # and add to the list of pulses
|
pulses += table[i] # and add to the list of pulses
|
||||||
pulses.pop() # remove one final 'low' pulse
|
pulses.pop() # remove one final 'low' pulse
|
||||||
|
|
||||||
for i in range(repeat):
|
for i in range(repeat):
|
||||||
pulse.send(array.array('H', pulses))
|
pulse.send(array.array('H', pulses))
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
led.value = False
|
led.value = False
|
||||||
time.sleep(code['delay'])
|
time.sleep(code['delay'])
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import analogio
|
import analogio
|
||||||
import board
|
import board
|
||||||
import pulseio
|
import pulseio
|
||||||
|
|
||||||
sampleWindow = 0.033 # Sample window width (0.033 sec = 33 mS = ~30 Hz)
|
sampleWindow = 0.033 # Sample window width (0.033 sec = 33 mS = ~30 Hz)
|
||||||
ledPin = board.D0 # Pin where LEDs are connected (PWM not avail on D1)
|
ledPin = board.D0 # Pin where LEDs are connected (PWM not avail on D1)
|
||||||
micPin = board.A1 # Microphone 'OUT' is connected here
|
micPin = board.A1 # Microphone 'OUT' is connected here
|
||||||
|
|
||||||
mic = analogio.AnalogIn(micPin)
|
mic = analogio.AnalogIn(micPin)
|
||||||
pwm = pulseio.PWMOut(ledPin, frequency=1000, duty_cycle=0)
|
pwm = pulseio.PWMOut(ledPin, frequency=1000, duty_cycle=0)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# Listen to mic for short interval, recording min & max signal
|
# Listen to mic for short interval, recording min & max signal
|
||||||
signalMin = 65535
|
signalMin = 65535
|
||||||
signalMax = 0
|
signalMax = 0
|
||||||
startTime = time.monotonic()
|
startTime = time.monotonic()
|
||||||
while (time.monotonic() - startTime) < sampleWindow:
|
while (time.monotonic() - startTime) < sampleWindow:
|
||||||
signal = mic.value
|
signal = mic.value
|
||||||
if signal < signalMin:
|
if signal < signalMin:
|
||||||
signalMin = signal
|
signalMin = signal
|
||||||
if signal > signalMax:
|
if signal > signalMax:
|
||||||
signalMax = signal
|
signalMax = signal
|
||||||
|
|
||||||
peakToPeak = signalMax - signalMin # Audio amplitude
|
peakToPeak = signalMax - signalMin # Audio amplitude
|
||||||
n = (peakToPeak - 250) * 4 # Remove low-level noise, boost
|
n = (peakToPeak - 250) * 4 # Remove low-level noise, boost
|
||||||
if n > 65535:
|
if n > 65535:
|
||||||
n = 65535 # Limit to valid PWM range
|
n = 65535 # Limit to valid PWM range
|
||||||
elif n < 0:
|
elif n < 0:
|
||||||
n = 0
|
n = 0
|
||||||
pwm.duty_cycle = n # And send to LED as PWM level
|
pwm.duty_cycle = n # And send to LED as PWM level
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,32 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
|
|
||||||
numpix = 5 # Number of NeoPixels
|
numpix = 5 # Number of NeoPixels
|
||||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||||
hue = 0 # Starting color
|
hue = 0 # Starting color
|
||||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.4)
|
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.4)
|
||||||
|
|
||||||
|
|
||||||
def wheel(pos):
|
def wheel(pos):
|
||||||
# Input a value 0 to 255 to get a color value.
|
# Input a value 0 to 255 to get a color value.
|
||||||
# The colours are a transition r - g - b - back to r.
|
# The colours are a transition r - g - b - back to r.
|
||||||
if (pos < 0) or (pos > 255):
|
if (pos < 0) or (pos > 255):
|
||||||
return [0, 0, 0]
|
return [0, 0, 0]
|
||||||
elif pos < 85:
|
elif pos < 85:
|
||||||
return [int(pos * 3), int(255 - (pos * 3)), 0]
|
return [int(pos * 3), int(255 - (pos * 3)), 0]
|
||||||
elif pos < 170:
|
elif pos < 170:
|
||||||
pos -= 85
|
pos -= 85
|
||||||
return [int(255 - pos * 3), 0, int(pos * 3)]
|
return [int(255 - pos * 3), 0, int(pos * 3)]
|
||||||
else:
|
else:
|
||||||
pos -= 170
|
pos -= 170
|
||||||
return [0, int(pos * 3), int(255 - pos * 3)]
|
return [0, int(pos * 3), int(255 - pos * 3)]
|
||||||
|
|
||||||
|
|
||||||
while True: # Loop forever...
|
while True: # Loop forever...
|
||||||
for i in range(numpix):
|
for i in range(numpix):
|
||||||
strip[i] = wheel((hue + i * 8) & 255)
|
strip[i] = wheel((hue + i * 8) & 255)
|
||||||
strip.write()
|
strip.write()
|
||||||
time.sleep(0.02) # 20 ms = ~50 fps
|
time.sleep(0.02) # 20 ms = ~50 fps
|
||||||
hue = (hue + 1) & 255 # Increment hue and 'wrap around' at 255
|
hue = (hue + 1) & 255 # Increment hue and 'wrap around' at 255
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,31 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import digitalio
|
import digitalio
|
||||||
import neopixel
|
import neopixel
|
||||||
|
|
||||||
numpix = 8 # Number of NeoPixels
|
numpix = 8 # Number of NeoPixels
|
||||||
ledpin = board.D1 # Digital pin # where NeoPixels are connected
|
ledpin = board.D1 # Digital pin # where NeoPixels are connected
|
||||||
sensorpin = board.D2 # Digital pin # where light sensor is connected
|
sensorpin = board.D2 # Digital pin # where light sensor is connected
|
||||||
strip = neopixel.NeoPixel(ledpin, numpix, brightness=1.0)
|
strip = neopixel.NeoPixel(ledpin, numpix, brightness=1.0)
|
||||||
|
|
||||||
# Enable internal pullup resistor on sensor pin
|
# Enable internal pullup resistor on sensor pin
|
||||||
pin = digitalio.DigitalInOut(sensorpin)
|
pin = digitalio.DigitalInOut(sensorpin)
|
||||||
pin.direction = digitalio.Direction.INPUT
|
pin.direction = digitalio.Direction.INPUT
|
||||||
pin.pull = digitalio.Pull.UP
|
pin.pull = digitalio.Pull.UP
|
||||||
|
|
||||||
while True: # Loop forever...
|
while True: # Loop forever...
|
||||||
|
|
||||||
# LDR is being used as a digital (binary) sensor. It must be
|
# LDR is being used as a digital (binary) sensor. It must be
|
||||||
# completely dark to turn it off, a finger may not be opaque enough!
|
# completely dark to turn it off, a finger may not be opaque enough!
|
||||||
if pin.value:
|
if pin.value:
|
||||||
color = (0, 0, 0) # Off
|
color = (0, 0, 0) # Off
|
||||||
else:
|
else:
|
||||||
color = (255, 0, 255) # Purple
|
color = (255, 0, 255) # Purple
|
||||||
|
|
||||||
for i in range(numpix): # For each pixel...
|
for i in range(numpix): # For each pixel...
|
||||||
strip[i] = color # Set to 'color'
|
strip[i] = color # Set to 'color'
|
||||||
strip.write() # Push data to pixels
|
strip.write() # Push data to pixels
|
||||||
time.sleep(0.05) # Pause 50 ms
|
time.sleep(0.05) # Pause 50 ms
|
||||||
|
|
||||||
time.sleep(0.002) # Pause 2 ms
|
time.sleep(0.002) # Pause 2 ms
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue