Skip to content

Commit bc52aa9

Browse files
committed
Fiber Optic Code
Code for fiber optic system on the Playa Bike
1 parent 8fe43d0 commit bc52aa9

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Playa_Bike/fiberoptic_code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import time
2+
import board
3+
import adafruit_rgbled
4+
import digitalio
5+
6+
POWER_PIN = board.D10
7+
8+
enable = digitalio.DigitalInOut(POWER_PIN)
9+
enable.direction = digitalio.Direction.OUTPUT
10+
enable.value = True
11+
12+
# Pin the Red LED is connected to
13+
RED_LED = board.D11
14+
15+
# Pin the Green LED is connected to
16+
GREEN_LED = board.D12
17+
18+
# Pin the Blue LED is connected to
19+
BLUE_LED = board.D13
20+
21+
# Create the RGB LED object
22+
led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED)
23+
24+
# Optionally, you can also create the RGB LED object with inverted PWM
25+
# led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)
26+
27+
def wheel(pos):
28+
# Input a value 0 to 255 to get a color value.
29+
# The colours are a transition r - g - b - back to r.
30+
if pos < 0 or pos > 255:
31+
return 0, 0, 0
32+
if pos < 85:
33+
return int(255 - pos * 3), int(pos * 3), 0
34+
if pos < 170:
35+
pos -= 85
36+
return 0, int(255 - pos * 3), int(pos * 3)
37+
pos -= 170
38+
return int(pos * 3), 0, int(255 - (pos * 3))
39+
40+
def rainbow_cycle(wait):
41+
for i in range(255):
42+
i = (i + 1) % 256
43+
led.color = wheel(i)
44+
time.sleep(wait)
45+
46+
while True:
47+
# rainbow cycle the RGB LED
48+
rainbow_cycle(0.1)

0 commit comments

Comments
 (0)