Fixes line ending issues

This commit is contained in:
Kattni Rembor 2018-05-28 22:16:45 -04:00
parent dc1aac7767
commit 355447daff
6 changed files with 193 additions and 194 deletions

1
.gitattributes vendored
View file

@ -1 +0,0 @@
*.py text eol=lf

View file

@ -1,46 +1,46 @@
import time
import board
import pulseio
from digitalio import DigitalInOut, Direction
# PWM (fading) LEDs are connected on D0 (PWM not avail on D1)
pwm_leds = board.D0
pwm = pulseio.PWMOut(pwm_leds, frequency=1000, duty_cycle=0)
# digital LEDs connected on D2
digital_leds = DigitalInOut(board.D2)
digital_leds.direction = Direction.OUTPUT
brightness = 0 # how bright the LED is
fade_amount = 1285 # 2% steping of 2^16
counter = 0 # counter to keep track of cycles
while True:
# And send to LED as PWM level
pwm.duty_cycle = brightness
# change the brightness for next time through the loop:
brightness = brightness + fade_amount
print(brightness)
# reverse the direction of the fading at the ends of the fade:
if brightness <= 0:
fade_amount = -fade_amount
counter += 1
elif brightness >= 65535:
fade_amount = -fade_amount
counter += 1
# wait for 15 ms to see the dimming effect
time.sleep(.015)
# turns on the other LEDs every four times through the fade by
# checking the modulo of the counter.
# the modulo function gives you the remainder of
# the division of two numbers:
if counter % 4 == 0:
digital_leds.value = True
else:
digital_leds.value = False
import time
import board
import pulseio
from digitalio import DigitalInOut, Direction
# PWM (fading) LEDs are connected on D0 (PWM not avail on D1)
pwm_leds = board.D0
pwm = pulseio.PWMOut(pwm_leds, frequency=1000, duty_cycle=0)
# digital LEDs connected on D2
digital_leds = DigitalInOut(board.D2)
digital_leds.direction = Direction.OUTPUT
brightness = 0 # how bright the LED is
fade_amount = 1285 # 2% steping of 2^16
counter = 0 # counter to keep track of cycles
while True:
# And send to LED as PWM level
pwm.duty_cycle = brightness
# change the brightness for next time through the loop:
brightness = brightness + fade_amount
print(brightness)
# reverse the direction of the fading at the ends of the fade:
if brightness <= 0:
fade_amount = -fade_amount
counter += 1
elif brightness >= 65535:
fade_amount = -fade_amount
counter += 1
# wait for 15 ms to see the dimming effect
time.sleep(.015)
# turns on the other LEDs every four times through the fade by
# checking the modulo of the counter.
# the modulo function gives you the remainder of
# the division of two numbers:
if counter % 4 == 0:
digital_leds.value = True
else:
digital_leds.value = False

View file

@ -1,52 +1,52 @@
# Gemma M0 version of TVBgone!
import array
import time
import adafruit_dotstar
import board
import pulseio
from digitalio import DigitalInOut, Direction
pixel = adafruit_dotstar.DotStar(
board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
pixel.fill((0, 0, 0))
# Button to see output debug
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
pwm = pulseio.PWMOut(board.A1, frequency=38000,
duty_cycle=2 ** 15, variable_frequency=True)
pulse = pulseio.PulseOut(pwm)
time.sleep(0.5) # Give a half second before starting
# gooooo!
f = open("/codes.txt", "r")
for line in f:
code = eval(line)
print(code)
pwm.frequency = code['freq']
led.value = True
# If this is a repeating code, extract details
try:
repeat = code['repeat']
delay = code['repeat_delay']
except KeyError: # by default, repeat once only!
repeat = 1
delay = 0
# The table holds the on/off pairs
table = code['table']
pulses = [] # store the pulses here
# Read through each indexed element
for i in code['index']:
pulses += table[i] # and add to the list of pulses
pulses.pop() # remove one final 'low' pulse
for i in range(repeat):
pulse.send(array.array('H', pulses))
time.sleep(delay)
led.value = False
time.sleep(code['delay'])
f.close()
# Gemma M0 version of TVBgone!
import array
import time
import adafruit_dotstar
import board
import pulseio
from digitalio import DigitalInOut, Direction
pixel = adafruit_dotstar.DotStar(
board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
pixel.fill((0, 0, 0))
# Button to see output debug
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
pwm = pulseio.PWMOut(board.A1, frequency=38000,
duty_cycle=2 ** 15, variable_frequency=True)
pulse = pulseio.PulseOut(pwm)
time.sleep(0.5) # Give a half second before starting
# gooooo!
f = open("/codes.txt", "r")
for line in f:
code = eval(line)
print(code)
pwm.frequency = code['freq']
led.value = True
# If this is a repeating code, extract details
try:
repeat = code['repeat']
delay = code['repeat_delay']
except KeyError: # by default, repeat once only!
repeat = 1
delay = 0
# The table holds the on/off pairs
table = code['table']
pulses = [] # store the pulses here
# Read through each indexed element
for i in code['index']:
pulses += table[i] # and add to the list of pulses
pulses.pop() # remove one final 'low' pulse
for i in range(repeat):
pulse.send(array.array('H', pulses))
time.sleep(delay)
led.value = False
time.sleep(code['delay'])
f.close()

View file

@ -1,32 +1,32 @@
import time
import analogio
import board
import pulseio
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)
micPin = board.A1 # Microphone 'OUT' is connected here
mic = analogio.AnalogIn(micPin)
pwm = pulseio.PWMOut(ledPin, frequency=1000, duty_cycle=0)
while True:
# Listen to mic for short interval, recording min & max signal
signalMin = 65535
signalMax = 0
startTime = time.monotonic()
while (time.monotonic() - startTime) < sampleWindow:
signal = mic.value
if signal < signalMin:
signalMin = signal
if signal > signalMax:
signalMax = signal
peakToPeak = signalMax - signalMin # Audio amplitude
n = (peakToPeak - 250) * 4 # Remove low-level noise, boost
if n > 65535:
n = 65535 # Limit to valid PWM range
elif n < 0:
n = 0
pwm.duty_cycle = n # And send to LED as PWM level
import time
import analogio
import board
import pulseio
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)
micPin = board.A1 # Microphone 'OUT' is connected here
mic = analogio.AnalogIn(micPin)
pwm = pulseio.PWMOut(ledPin, frequency=1000, duty_cycle=0)
while True:
# Listen to mic for short interval, recording min & max signal
signalMin = 65535
signalMax = 0
startTime = time.monotonic()
while (time.monotonic() - startTime) < sampleWindow:
signal = mic.value
if signal < signalMin:
signalMin = signal
if signal > signalMax:
signalMax = signal
peakToPeak = signalMax - signalMin # Audio amplitude
n = (peakToPeak - 250) * 4 # Remove low-level noise, boost
if n > 65535:
n = 65535 # Limit to valid PWM range
elif n < 0:
n = 0
pwm.duty_cycle = n # And send to LED as PWM level

View file

@ -1,32 +1,32 @@
import time
import board
import neopixel
numpix = 5 # Number of NeoPixels
pixpin = board.D1 # Pin where NeoPixels are connected
hue = 0 # Starting color
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.4)
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]
elif 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)]
while True: # Loop forever...
for i in range(numpix):
strip[i] = wheel((hue + i * 8) & 255)
strip.write()
time.sleep(0.02) # 20 ms = ~50 fps
hue = (hue + 1) & 255 # Increment hue and 'wrap around' at 255
import time
import board
import neopixel
numpix = 5 # Number of NeoPixels
pixpin = board.D1 # Pin where NeoPixels are connected
hue = 0 # Starting color
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.4)
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]
elif 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)]
while True: # Loop forever...
for i in range(numpix):
strip[i] = wheel((hue + i * 8) & 255)
strip.write()
time.sleep(0.02) # 20 ms = ~50 fps
hue = (hue + 1) & 255 # Increment hue and 'wrap around' at 255

View file

@ -1,31 +1,31 @@
import time
import board
import digitalio
import neopixel
numpix = 8 # Number of NeoPixels
ledpin = board.D1 # Digital pin # where NeoPixels are connected
sensorpin = board.D2 # Digital pin # where light sensor is connected
strip = neopixel.NeoPixel(ledpin, numpix, brightness=1.0)
# Enable internal pullup resistor on sensor pin
pin = digitalio.DigitalInOut(sensorpin)
pin.direction = digitalio.Direction.INPUT
pin.pull = digitalio.Pull.UP
while True: # Loop forever...
# 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!
if pin.value:
color = (0, 0, 0) # Off
else:
color = (255, 0, 255) # Purple
for i in range(numpix): # For each pixel...
strip[i] = color # Set to 'color'
strip.write() # Push data to pixels
time.sleep(0.05) # Pause 50 ms
time.sleep(0.002) # Pause 2 ms
import time
import board
import digitalio
import neopixel
numpix = 8 # Number of NeoPixels
ledpin = board.D1 # Digital pin # where NeoPixels are connected
sensorpin = board.D2 # Digital pin # where light sensor is connected
strip = neopixel.NeoPixel(ledpin, numpix, brightness=1.0)
# Enable internal pullup resistor on sensor pin
pin = digitalio.DigitalInOut(sensorpin)
pin.direction = digitalio.Direction.INPUT
pin.pull = digitalio.Pull.UP
while True: # Loop forever...
# 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!
if pin.value:
color = (0, 0, 0) # Off
else:
color = (255, 0, 255) # Purple
for i in range(numpix): # For each pixel...
strip[i] = color # Set to 'color'
strip.write() # Push data to pixels
time.sleep(0.05) # Pause 50 ms
time.sleep(0.002) # Pause 2 ms