ported to CircuitPython
This commit is contained in:
parent
0657a10f60
commit
62e0db413e
5 changed files with 87 additions and 0 deletions
BIN
Adafruit_LED_Sequins/.DS_Store
vendored
Normal file
BIN
Adafruit_LED_Sequins/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Adafruit_LED_Sequins/Adafruit_LED_Sequins.fzz
Normal file
BIN
Adafruit_LED_Sequins/Adafruit_LED_Sequins.fzz
Normal file
Binary file not shown.
37
Adafruit_LED_Sequins/Adafruit_LED_Sequins.ino
Normal file
37
Adafruit_LED_Sequins/Adafruit_LED_Sequins.ino
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
int brightness = 0; // how bright the LED is
|
||||
int fadeAmount = 5; // how many points to fade the LED by
|
||||
int counter = 0; // counter to keep track of cycles
|
||||
|
||||
// the setup routine runs once when you press reset:
|
||||
void setup() {
|
||||
// declare pins to be an outputs:
|
||||
pinMode(0, OUTPUT);
|
||||
pinMode(2, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop routine runs over and over again forever:
|
||||
void loop() {
|
||||
// set the brightness of the analog-connected LEDs:
|
||||
analogWrite(0, brightness);
|
||||
|
||||
// change the brightness for next time through the loop:
|
||||
brightness = brightness + fadeAmount;
|
||||
|
||||
// reverse the direction of the fading at the ends of the fade:
|
||||
if (brightness == 0 || brightness == 255) {
|
||||
fadeAmount = -fadeAmount;
|
||||
counter++;
|
||||
}
|
||||
// wait for 15 milliseconds to see the dimming effect
|
||||
delay(15);
|
||||
|
||||
// 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) {
|
||||
digitalWrite(2, HIGH);
|
||||
} else {
|
||||
digitalWrite(2, LOW);
|
||||
}
|
||||
}
|
||||
46
Adafruit_LED_Sequins/Adafruit_LED_Sequins.py
Normal file
46
Adafruit_LED_Sequins/Adafruit_LED_Sequins.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import board
|
||||
import pulseio
|
||||
import time
|
||||
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
|
||||
4
Adafruit_LED_Sequins/README.md
Normal file
4
Adafruit_LED_Sequins/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Adafruit_LED_Sequins
|
||||
|
||||
Code to accompany this tutorial:
|
||||
https://learn.adafruit.com/adafruit-led-sequins/
|
||||
Loading…
Reference in a new issue