controllables.LED
- class controllables.LED(port: Optional[int] = None)
Reference to the LED part.
The following code block assumes that an LED is assigned to port
0
.from controllables import LED from color import Color from time import time from math import sin, tau, pow led = LED(0) # how long each pulse will last pulse_length = 1 # the higher the punchiness the quicker the light flashes punchiness = 4 while True: # sample a sin wave with period pulse_length intensity = sin(time() * tau / pulse_length) # put it between 0 and 1 intensity = (1 + intensity) / 2. # raise intensity to a power to sharpen the curve intensity = pow(intensity,punchiness) led.color = Color(red=intensity, green=0, blue=0)
- turn_on(power: float = 1)
Turns the LED on.
power
should be assigned to afloat
between0
to1
representing the brightness of the LED.from controllables import LED import time led = LED(0) led.turn_on() time.sleep(1) led.turn_off()
- turn_off()
Turns the LED off.
Note
This doesn’t prevent transmitters or properties from turning the LED on.
from controllables import LED import time led = LED(0) led.turn_on() time.sleep(1) led.turn_off()
- property color: Color
The color of the LED.
from controllables import LED from time import sleep from color import Color led = LED(0) # assign color with a preset color name led.color = "red" led.turn_on() sleep(2) led.turn_off() sleep(1) # assign color with Color object led.color = Color(0,1,0) led.turn_on() sleep(2) led.turn_off() sleep(1) # assign color with hexcode string led.color = "#0000ff" led.turn_on()
- power() float
The power being sent to the LED from 0 to 1.
from controllables import LED, TextScreen led = LED(0) screen = TextScreen(1) while True: screen.text = f'led.power(): {led.power(): 0.2f}'
- name() str
Returns the user editable name of the controllable as found in the properties tab of the game.
The following example assumes that any controllable or sensor is assigned to port
0
and prints out its name.from ports import PortReference print(PortReference(0).name())