class Draw: def __init__(self, pin_led_status, image_name): print("Draw the image") self.led_status = PWMLED(pin_led_status) self.image_name = image_name self._bg = BrachioGraph( inner_arm=os.environ.get('ARM_INNER') or 8, # Upper arm length cm outer_arm=os.environ.get('ARM_OUTER') or 8, # Underarm length cm # Coordinates drawing area bounds=(-8, 4, 4, 13), servo_1_degree_ms=-10, # Movement shoulder servo servo_2_degree_ms=10, # Movement elbow servo servo_1_centre=1500, # Middle position shoulder servo_2_centre=1500, # Middle position elbow pw_down=os.environ.get('PW_DOWN') or 1850, # Position pin bottom pw_up=os.environ.get('PW_UP') or 1500, # Position pin lifted ) self._draw(self) def _draw(self): self.led_status.pulse(.1) sleep(1) self._bg.box() self._bg.plot_file('images/%s.json' % self.image_name) sleep(1) self.led_status.value = .9
class PWMLEDIndicator(object): """ A pulse-width modulated LED. """ def __init__(self, gpio_pin, brightness=100): """ Constructor of a PWM LED. :param gpio_pin: GPIO pin assignment (not the header pin number) :param brightness: Brightness percentage. Defaults to 100%. """ self.led = PWMLED(gpio_pin) self.brightness = brightness / 100.0 # brightness value is from 0 to 1.0 def turn_on(self): # ~ self.led.on() self.led.value = self.brightness def turn_off(self): # ~ self.led.off() self.led.value = 0 def blink(self, max_times=10): # blink in a separate thread self.led.blink(0.5, 0.2, n=max_times) def pulse(self, max_times=10): # pulse in a separate thread self.led.pulse(n=max_times) def close(self): self.led.close()
def main(): firstRun = True lastRunTimestamp = time.time() players = [] numOnline = 0 redLed = PWMLED(redPin) while True: if (lastRunTimestamp + 300) < time.time() or firstRun == True: firstRun = False lastRunTimestamp = time.time() try: f = open(confFile, 'r') serverInfo = json.loads(f.read()) f.close() #print("checking server status. " + str(time.time())) r = requests.get("https://api.mcsrvstat.us/2/" + serverInfo['ipAddress'], timeout=10).json() numOnline = r['players']['online'] if numOnline > 0: players = r['players']['list'] redLed.pulse() #print(players) else: players = [] redLed.off() #print("didn't find any players") except Exception as e: redLed.blink(0.5,0.5,0,0,15,True) scrollText("Something went wrong") if numOnline > 0: scrollText(listToString(players)) else: scrollText("no one online")
class ResultsLed: def __init__(self, pin): self.led = PWMLED(pin) self.conversion = 1 / 100 def update(self, light_value): decimal_time = light_value * self.conversion self.led.pulse(decimal_time, decimal_time)
class Convert: def __init__(self, pin_led_status, image_name): print("Convert the photo to an image") self.led_status = PWMLED(pin_led_status) self.image_name = image_name self._render(self) def _render(self): self.led_status.pulse(.1) sleep(1) image_to_json(self.image_name, draw_contours=2, draw_hatch=16) self.led_status.value = .9
def main(): # now just write the code you would use in a real Raspberry Pi from Adafruit_CharLCD import Adafruit_CharLCD from gpiozero import Buzzer, LED, PWMLED, Button, DistanceSensor, LightSensor, MotionSensor from lirc import init, nextcode from py_irsend.irsend import send_once from time import sleep def show_sensor_values(): lcd.clear() lcd.message( "Distance: %.2fm\nLight: %d%%" % (distance_sensor.distance, light_sensor.value * 100) ) def send_infrared(): send_once("TV", ["KEY_4", "KEY_2", "KEY_OK"]) lcd = Adafruit_CharLCD(2, 3, 4, 5, 6, 7, 16, 2) buzzer = Buzzer(16) led1 = LED(21) led2 = LED(22) led3 = LED(23) led4 = LED(24) led5 = PWMLED(25) led5.pulse() button1 = Button(11) button2 = Button(12) button3 = Button(13) button4 = Button(14) button1.when_pressed = led1.toggle button2.when_pressed = buzzer.on button2.when_released = buzzer.off button3.when_pressed = show_sensor_values button4.when_pressed = send_infrared distance_sensor = DistanceSensor(trigger=17, echo=18) light_sensor = LightSensor(8) motion_sensor = MotionSensor(27) motion_sensor.when_motion = led2.on motion_sensor.when_no_motion = led2.off init("default") while True: code = nextcode() if code != []: key = code[0] lcd.clear() lcd.message(key + "\nwas pressed!") sleep(0.2)
def main(): led = PWMLED(conf.LED_PIN) led.blink() # each item in conf.BTNS[] is an individual button setting for this in conf.BTNS: this['button'] = Button(this['PIN']) this['button']when_released = put_curry(this['LABEL']) print("ready!") led.pulse() pause()
def main(): # setup # See https://www.raspberrypi.org/documentation/usage/gpio/ # Pins are on the edge of the connector, right next to each-other # Indicator should connect the positive side (anode, yellow wire) to GPIO pin 23 # and negative side (cathode, orange wire) to ground # Button should connect 3V3 (blue wire) to GPIO pin 24 (green wire) away_indicator = PWMLED(pin=18, active_high=False, initial_value=False) home_indicator = LED(pin=23, active_high=False, initial_value=False) button = Button(pin=17, pull_up=False) button.when_held = handle_button button.hold_time = 0.5 # Setup logging logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) handler = logging.StreamHandler() handler.setLevel(logging.INFO) handler.setFormatter( logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) # This is used to communicate the state relatively "thread-safely" # to the Sopel bot presence_file = Path(PRESENCE_FILE) # Prime the state from file, defaults to False if file does not exist last_state = state = read_state(presence_file) logger.info('Starting main loop') while True: # Update the state from file state = read_state(presence_file) # Check if state changed if state != last_state: # Set LED based on the state if state: home_indicator.on() away_indicator.off() else: home_indicator.off() away_indicator.pulse(fade_in_time=1, fade_out_time=3) logger.info('Toggling LED state: %s', 'on' if state else 'off') last_state = state # Sleep before next round sleep(0.5)
class ButtonPressRelease: def __init__(self): self.button = Button(2) self.led = PWMLED(17) def continuously_listen(self): while True: if self.button.is_pressed: self.print_message_pressed() else: self.print_message_released() def wait_for_being_pressed(self): self.button.wait_for_press() self.print_message_pressed(False) def when_pressed_or_released_print_something(self): self.button.when_pressed = self.print_message_pressed self.button.when_released = self.print_message_released pause() def turn_on_off_led(self): self.button.when_released = self.turn_off_led self.button.when_pressed = self.led_pulse pause() def print_message_pressed(self, is_continous=True): if is_continous: tense = "is" else: tense = "was" print("Button " + tense + " pressed.") def print_message_released(self): print("Button is released.") def led_pulse(self): self.print_message_pressed(True) self.led.pulse() def turn_off_led(self): self.print_message_released() self.led.off()
def breathing_light(pin: int, fade_in_time: float = 1, fade_out_time: float = 1): """LED 呼吸灯. 电路图: 同 001 https://crcit.net/c/6f31f46af16541528a91698b4ea109a1 使用 PWMLED 即可简单的实现该功能. PWMLED 与 普通的 LED 对比, 可以更精细的控制 value 值. LED 的 value 值类型为 bool, 即只能是 True 或者 False. 而 PWMLED 的 value 值类型为 float, 可以是 0 到 1 之间的任何值. Args: pin (int): 接有 LED 灯的管脚. fade_in_time (int, optional): 淡入时间, 单位秒. 默认 1. fade_out_time (int, optional): 淡出时间, 单位秒. 默认 1. """ light = PWMLED(pin) light.pulse(fade_in_time=fade_in_time, fade_out_time=fade_out_time)
def main(): # LEDピン設定 factory = PiGPIOFactory() led = PWMLED(PIN_LED1, pin_factory=factory) # だんだん明るくする # 25% -> 50% -> 75% -> 100% led.value = 0.25 sleep(1) led.value = 0.50 sleep(1) led.value = 0.75 sleep(1) led.value = 1.0 sleep(1) # 徐々に明るくし、徐々に暗くするを繰り返す try: led.pulse() pause() except KeyboardInterrupt: print("stop") led.off()
from gpiozero import LEDBoard from gpiozero import PWMLED from time import sleep tree = LEDBoard(6, 7, 8) tree1 = LEDBoard(13, 16, 20) tree2 = LEDBoard(19, 21, 26) tree3 = LEDBoard(9, 10, 22) tree4 = LEDBoard(23, 24, 25) tree5 = LEDBoard(15, 18, 27) tree6 = LEDBoard(4, 17, 14) tree7 = LEDBoard(5, 11, 12) tree8 = PWMLED(2) #This is the star while True: tree8.pulse() #Put this first so it starts immediately tree.on() sleep(0.5) tree.off() tree1.on() sleep(0.5) tree1.off() tree2.on() sleep(0.5) tree2.off() tree3.on() sleep(1) tree3.off() tree4.on() sleep(0.5) tree4.off()
from signal import pause from time import sleep from gpiozero import PWMLED l = PWMLED(17) # for i in range(0, 100): # v = float(i) / 100 # print v # l.value = v # sleep(0.1) l.pulse() pause()
try: # Add the overlay with the padded image as the source, # but the original image's dimensions # note: we need to hflip the overlay only if vfliped o = camera.add_overlay(acc.tobytes(), format='rgba', vflip=camera.vflip, hflip=camera.vflip) # By default, the overlay is in layer 0, beneath the # preview (which defaults to layer 2). Here we make # the new overlay semi-transparent, then move it above # the preview #o.alpha = 128 o.layer = 3 led.pulse(2, 2) button.wait_for_press() camera.remove_overlay(o) ledStrip.on() #led.blink (on_time=0.125, off_time=0.125, n=16, background=True) #led2.blink (on_time=0.125, off_time=0.125, n=16, background=True) # blink leds to show waiting time led2.pulse(fade_in_time=0.125, fade_out_time=0.125, n=16, background=True) led.pulse(fade_in_time=0.125, fade_out_time=0.125,
from gpiozero import PWMLED from time import sleep led = PWMLED(26) led.pulse(fade_in_time=2, fade_out_time=1, n=5)
def flashtwo(): led = PWMLED(4) led.pulse() pause()
class PWMLedPlugin(PluginProcessBase): def __init__(self): self._bcm_pin = SETTINGS.pwm_led.get('bcm_pin', default=None, cast_to_type=int, ge=0, le=27, allow_none=True) self._frequency = SETTINGS.pwm_led.get('frequency', default=100, cast_to_type=int, ge=10, le=10000) self._pwmled = None self._active = False self._rebuild_pwmled() def _rebuild_pwmled(self): old_value = 0. if self._pwmled is not None: if not self._active or self._bcm_pin is None: _log.info('Disabling PWM led.') else: old_value = self._pwmled.value self._pwmled.off() self._pwmled = None if self._bcm_pin is not None and self._active: _log.info('Rebuilding PWM led on pin %d with frequency %d.', self._bcm_pin, self._frequency) self._pwmled = PWMLED(self.bcm_pin, frequency=self.frequency, initial_value=old_value) def __enter__(self): self._active = True self._rebuild_pwmled() return self def __exit__(self, exc_type, exc_val, exc_tb): self._active = False self._rebuild_pwmled() @pyro_expose @property def frequency(self): return self._frequency @pyro_expose @frequency.setter def frequency(self, value): value = min(max(int(value), 10), 10000) if value != self._frequency: self._frequency = value self._rebuild_pwmled() @pyro_expose @property def bcm_pin(self): return self._bcm_pin @pyro_expose @bcm_pin.setter def bcm_pin(self, value): value = min(max(int(value), 0), 27) if value != self._bcm_pin: self._bcm_pin = value self._rebuild_pwmled() @pyro_expose @property def is_lit(self): if self._pwmled is not None: return self._pwmled.is_lit return None @pyro_expose @property def value(self): return None if self._pwmled is None else self._pwmled.value @pyro_expose @value.setter def value(self, v): if self._pwmled is not None: _log.info('Setting PWM led on pin %d to value %s.', self.bcm_pin, str(v)) try: old_v = self._pwmled.value with Status.custom((old_v, old_v, old_v), (v, v, v), fade_out_time=0.5, persist_on_time=0.25, persist_off_time=0.25, n=1): self._pwmled.value = v except Exception as e: # pragma: no cover _log.exception('Unable to set value to %s.', str(v)) raise e @pyro_expose @pyro_oneway def on(self): if self._pwmled is not None: _log.info('Turning on PWM led on pin %d.' % self.bcm_pin) self.value = 1. @pyro_expose @pyro_oneway def off(self): if self._pwmled is not None: _log.info('Turning off PWM led on pin %d.' % self.bcm_pin) self.value = 0. @pyro_expose @pyro_oneway def toggle(self): if self._pwmled is not None: if self.is_lit: self.off() else: self.on() @pyro_expose @pyro_oneway def pulse(self): if self._pwmled is not None: _log.info('Pulsating PWM led on pin %d.', self.bcm_pin) try: self._pwmled.pulse(n=5) except Exception as e: # pragma: no cover _log.exception('Pulse failed!') raise e
from gpiozero import PWMLED from signal import pause led = PWMLED(17) led.pulse() pause()
#!/usr/bin/python3 from gpiozero import PWMLED from signal import pause red = PWMLED(21) print("Press Crtl-C to stop the program.") while True: try: red.pulse() pause() except KeyboardInterrupt: print("Stopping program.\n") red.close() exit()
from gpiozero import PWMLED from time import sleep red = PWMLED(14) blue = PWMLED(15) yellow = PWMLED(18) while True: red.pulse(0.3, 0.3, 4, True) blue.pulse(0.4, 0.4, 3, True) yellow.pulse(0.6, 0.6, 2, True) sleep(2.4) # PWMLEDs have a pulse command. The parameters are: # 1 Fade in time, in seconds # 2 Fade out time, in seconds # 3 Number of times to pulse # 4 Background - True to continue to the next command without waiting # False to wait until finished # # For example: # red.pulse(0.3,0.3,4,True) # * Fade in for 0.3 seconds # * Fade out for 0.3 seconds # * Repeat 4 times # * Continue with the next command without waiting # 4x0.3=1.2 seconds to fade in # 4x0.3=1.2 seconds to fade out # 1.2+1.2=2.4 seconds total # # Find out more about PWMLED commands
from gpiozero import PWMLED from signal import pause led = PWMLED(17) led.pulse() # pulse - fade in and out continously pause()
from gpiozero import PWMLED, Button from time import sleep led = PWMLED(26) button = Button(12) while True: button.wait_for_press() led.pulse(n=1)
from gpiozero.pins.pigpio import PiGPIOFactory from gpiozero import PWMLED from time import sleep factory = PiGPIOFactory() led = PWMLED(12, pin_factory=factory) """ while True: for duty in range(0,100,1): led.value = duty/100.0 sleep(0.05) for duty in range(100,0,-1): led.value = duty/100.0 sleep(0.05) """ led.pulse(2, 2, n=5, background=False)
data = {"co2": ppm, "temp": temperature, "humidity": humidity} log_to_influxdb(data) time.sleep(1) except Exception as error: print(error) if __name__ == "__main__": print("CO2Zero startet, bitte warten...") pwm_g = PWMLED(17) pwm_y = PWMLED(27) pwm_r = PWMLED(22) pwm_g.pulse() pwm_y.pulse() pwm_r.pulse() read_config() init_influxdb() lcd.lcd_init() lcd.lcd_string("CO2Zero startet,", lcd.LCD_LINE_1) lcd.lcd_string("bitte warten ...", lcd.LCD_LINE_2) time.sleep(5) pwm_g.close() pwm_y.close() pwm_r.close()
#brightness.ChangeDutyCycle(100) #newLed.on() thread = threading.Thread(target=blinkenLighten) thread.start() logging.debug('Fan TURNED ON ' + str(int(currentTemp)) + ' - aiming for ' + str(int(temp))) else: logging.debug('Fan ALREADY ON ' + str(int(currentTemp)) + ' - aiming for ' + str(int(temp))) i = int(i) - 1 else: if status == 'on': off += 1 if off > (tries): #time.sleep(int(tries) * 5) newLed.pulse() targetFile.write('0') targetFile.close() fanStatus.write('off|' + str(int(currentTemp))) fanStatus.close() #GPIO.output(16, GPIO.LOW) #brightness.ChangeDutyCycle(0) newLed.off() logging.debug('Fan TURNED OFF ' + str(int(currentTemp)) + ' - aiming for ' + str(int(temp))) off = 0 status = 'off' i = 0 else: #brightnessLevel = ((int(tries) - off) / 100) #newLed.value = brightnessLevel
from gpiozero import LEDBoard, PWMLED from gpiozero.tools import random_values from signal import pause from time import sleep #tree = LEDBoard(*range(2,28),pwm=True) #for led in range(2,28): # poo=PWMLED(led) # print led # poo.on() # sleep(10) # poo.off() star = PWMLED(2) star.pulse() row1 = [19] row2 = [11, 27, 17, 25, 16] row3 = [8, 26, 5, 4, 9, 13] row4 = [6, 18, 15, 12, 22, 24, 20] row5 = [7, 21, 14, 10, 23] rows = [row1, row2, row3, row4, row5] lights = [] #while True: for item in rows: for lednum in item: light = PWMLED(lednum) light.blink(on_time=0.1,
from gpiozero import PWMLED led = PWMLED(21) led.pulse( fade_in_time=0.5, # tiempo hasta encenderse fade_out_time=2, # tiempo hasta apagarse background=False # ejecutar en primer plano )
import datetime import json as simplejson # api-endpoint url = "<ENTER END POINT>" headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} #startup led = PWMLED(17) now = datetime.datetime.now() timestamp = now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000)) data = {'id': 'meeseeks001', 'datetime': timestamp, 'message': 'Meeseeks Box On'} requests.post(url, data=simplejson.dumps(data), headers=headers) led.pulse(n=2, background=False) led.value = 1 def send_logicapp(): led.blink(on_time=.1, off_time=.1,n=1,background=False) led.value = 1 # get timestamp now = datetime.datetime.now() timestamp = now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000)) data = {'id': 'meeseeks001', 'datetime': timestamp, 'message': 'Button Push'} requests.post(url, data=simplejson.dumps(data), headers=headers) print("LogicApp Request Sent! : " + timestamp) def shutdown():
from gpiozero import PWMLED from signal import pause led = PWMLED(18) led.pulse() pause()
class KillTeam: def __init__(self): self.plusButton = Button(17) self.minusButton = Button(27) self.okButton = Button(22) self.canticleLed1 = PWMLED(5) # IncantationOfTheIronSoul self.canticleLed2 = PWMLED(6) # LitanyOfTheElectromancer self.canticleLed3 = PWMLED(13) # Chant of the Remorseless Fist self.canticleLed4 = PWMLED(19) # Shroudpsalm self.canticleLed5 = PWMLED(26) # Invocation of Machine Might self.canticleLed6 = PWMLED(21) # Benediction of the Omnissiah self.initiativeLed = PWMLED(23) self.movementLed = PWMLED(24) self.psychicLed = PWMLED(25) self.shootingLed = PWMLED(12) self.meleeLed = PWMLED(16) self.moraleLed = PWMLED(20) self.selected_canticle = INCANTATION_OF_THE_IRON_SOUL self.canticle1Used = False self.canticle2Used = False self.canticle3Used = False self.canticle4Used = False self.canticle5Used = False self.canticle6Used = False self.continueGame = True def select_canticles(self): self.initiativeLed.off() self.movementLed.off() self.psychicLed.off() self.shootingLed.off() self.meleeLed.off() self.moraleLed.off() self.plusButton.when_pressed = self.canticle_plus_button self.minusButton.when_pressed = self.canticle_minus_button self.okButton.when_pressed = self.canticle_ok_button self.display_canticle() self.okButton.wait_for_press() self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None sleep(0.5) def canticle_plus_button(self): self.selected_canticle += 1 if self.selected_canticle == 8: self.selected_canticle = INCANTATION_OF_THE_IRON_SOUL self.display_canticle() def canticle_minus_button(self): self.selected_canticle -= 1 if self.selected_canticle == -1: self.selected_canticle = BENEDICTION_OF_THE_OMNISSIAH self.display_canticle() def canticle_ok_button(self): if self.selected_canticle == 0 or self.selected_canticle == 7: self.selected_canticle = randint(1, 6) else: if self.selected_canticle == INCANTATION_OF_THE_IRON_SOUL: self.canticle1Used = True elif self.selected_canticle == LITANY_OF_THE_ELECTROMANCER: self.canticle2Used = True elif self.selected_canticle == CHANT_OF_THE_REMORSELESS_FIST: self.canticle3Used = True elif self.selected_canticle == SHROUDPSALM: self.canticle4Used = True elif self.selected_canticle == INVOCATION_OF_MACHINE_MIGHT: self.canticle5Used = True elif self.selected_canticle == BENEDICTION_OF_THE_OMNISSIAH: self.canticle6Used = True self.display_canticle(True) def initiative_phase(self): self.initiativeLed.on() self.movementLed.off() self.psychicLed.off() self.shootingLed.off() self.meleeLed.off() self.moraleLed.off() self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None self.okButton.wait_for_press() sleep(0.5) def movement_phase(self): self.initiativeLed.off() self.movementLed.on() self.psychicLed.off() self.shootingLed.off() self.meleeLed.off() self.moraleLed.off() self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None self.okButton.wait_for_press() sleep(0.5) def psychic_phase(self): self.initiativeLed.off() self.movementLed.off() self.psychicLed.on() self.shootingLed.off() self.meleeLed.off() self.moraleLed.off() self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None self.okButton.wait_for_press() sleep(0.5) def shooting_phase(self): self.initiativeLed.off() self.movementLed.off() self.psychicLed.off() self.shootingLed.on() self.meleeLed.off() self.moraleLed.off() if self.selected_canticle in [ SHROUDPSALM, BENEDICTION_OF_THE_OMNISSIAH ]: self.display_canticle(True, True) self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None self.okButton.wait_for_press() if self.selected_canticle in [ SHROUDPSALM, BENEDICTION_OF_THE_OMNISSIAH ]: self.display_canticle(True, False) sleep(0.5) def melee_phase(self): self.initiativeLed.off() self.movementLed.off() self.psychicLed.off() self.shootingLed.off() self.meleeLed.on() self.moraleLed.off() if self.selected_canticle in [ LITANY_OF_THE_ELECTROMANCER, CHANT_OF_THE_REMORSELESS_FIST, INVOCATION_OF_MACHINE_MIGHT ]: self.display_canticle(True, True) self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None self.okButton.wait_for_press() if self.selected_canticle in [ LITANY_OF_THE_ELECTROMANCER, CHANT_OF_THE_REMORSELESS_FIST, INVOCATION_OF_MACHINE_MIGHT ]: self.display_canticle(True, False) sleep(0.5) def morale_phase(self): self.initiativeLed.off() self.movementLed.off() self.psychicLed.off() self.shootingLed.off() self.meleeLed.off() self.moraleLed.on() if self.selected_canticle in [1]: self.display_canticle(True, True) self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None self.okButton.wait_for_press() if self.selected_canticle in [1]: self.display_canticle(True, False) sleep(0.5) def select_if_end_game(self): self.initiativeLed.pulse() self.movementLed.pulse() self.psychicLed.pulse() self.shootingLed.pulse() self.meleeLed.pulse() self.moraleLed.pulse() self.plusButton.when_pressed = None self.minusButton.when_pressed = self.end_game_select self.okButton.when_pressed = None self.okButton.wait_for_press() self.plusButton.when_pressed = None self.minusButton.when_pressed = None self.okButton.when_pressed = None sleep(0.5) def end_game_select(self): self.continueGame = not self.continueGame if self.continueGame: self.initiativeLed.pulse() self.movementLed.pulse() self.psychicLed.pulse() self.shootingLed.pulse() self.meleeLed.pulse() self.moraleLed.pulse() else: self.initiativeLed.off() self.movementLed.off() self.psychicLed.off() self.shootingLed.off() self.meleeLed.off() self.moraleLed.off() def close(self): self.initiativeLed.close() self.movementLed.close() self.psychicLed.close() self.shootingLed.close() self.meleeLed.close() self.moraleLed.close() self.canticleLed1.close() self.canticleLed2.close() self.canticleLed3.close() self.canticleLed4.close() self.canticleLed5.close() self.canticleLed6.close() self.plusButton.close() self.minusButton.close() self.okButton.close() def display_canticle(self, selected=False, blinking=False): if selected: self.canticleLed1.off() self.canticleLed2.off() self.canticleLed3.off() self.canticleLed4.off() self.canticleLed5.off() self.canticleLed6.off() if self.selected_canticle == 1: if blinking: self.canticleLed1.pulse() else: self.canticleLed1.on() elif self.selected_canticle == LITANY_OF_THE_ELECTROMANCER: if blinking: self.canticleLed2.pulse() else: self.canticleLed2.on() elif self.selected_canticle == CHANT_OF_THE_REMORSELESS_FIST: if blinking: self.canticleLed3.pulse() else: self.canticleLed3.on() elif self.selected_canticle == SHROUDPSALM: if blinking: self.canticleLed4.pulse() else: self.canticleLed4.on() elif self.selected_canticle == INVOCATION_OF_MACHINE_MIGHT: if blinking: self.canticleLed5.pulse() else: self.canticleLed5.on() elif self.selected_canticle == BENEDICTION_OF_THE_OMNISSIAH: if blinking: self.canticleLed6.pulse() else: self.canticleLed6.on() else: if not self.canticle1Used: self.canticleLed1.on() else: self.canticleLed1.off() if not self.canticle2Used: self.canticleLed2.on() else: self.canticleLed2.off() if not self.canticle3Used: self.canticleLed3.on() else: self.canticleLed3.off() if not self.canticle4Used: self.canticleLed4.on() else: self.canticleLed4.off() if not self.canticle5Used: self.canticleLed5.on() else: self.canticleLed5.off() if not self.canticle6Used: self.canticleLed6.on() else: self.canticleLed6.off() if self.selected_canticle == 1: self.canticleLed1.pulse() elif self.selected_canticle == LITANY_OF_THE_ELECTROMANCER: self.canticleLed2.pulse() elif self.selected_canticle == CHANT_OF_THE_REMORSELESS_FIST: self.canticleLed3.pulse() elif self.selected_canticle == SHROUDPSALM: self.canticleLed4.pulse() elif self.selected_canticle == INVOCATION_OF_MACHINE_MIGHT: self.canticleLed5.pulse() elif self.selected_canticle == BENEDICTION_OF_THE_OMNISSIAH: self.canticleLed6.pulse() else: self.canticleLed1.pulse() self.canticleLed2.pulse() self.canticleLed3.pulse() self.canticleLed4.pulse() self.canticleLed5.pulse() self.canticleLed6.pulse()
from gpiozero import LED from gpiozero import PWMLED from time import sleep sololed = PWMLED(17) for i in range(0,3): sololed.on() sleep(.5) sololed.off() sleep(.5) print("begin pulsing") sololed.pulse(n=3,background=False) print("end pulsing") led=[] sleeptime=.01 for i in range(0,10): led.append(LED(i+2)) while True: for i in range(0,10): print("{} on".format(i)) led[i].on() sleep(sleeptime) print(" off") led[i].off() sleep(sleeptime) for i in range(9,-1,-1): print("{} on".format(i))
from time import sleep l1 = LED(17) l2 = LED(18) l3 = PWMLED(19) l4 = LED(20) l4.on() l1.on() sleep(1) l2.on() sleep(1) l3.pulse() sleep(1) l1.off() sleep(1) l1.off() sleep(1) #l3.off() #sleep(1) l4.off()