def __init__(self): self.led1_w = LED(17) self.led2_w = LED(11) self.sensor = Button(24) self.button = Button(23) self.button.when_pressed = self.__exit self.timers = {} self.timers[1] = time.time() self.leds = {} self.leds[1] = {'o': RGBLED(2, 3, 4, pwm=True, active_high=False), 'c': (1, 1, 1), 'b': 1.} self.leds[2] = {'o': RGBLED(10, 9, 25, pwm=True, active_high=False), 'c': (1, 1, 1), 'b': 1.}
def add_led(self, name, pins): assert (not self.leds.get(name)), f"LED {name} already exists!" logger.info(f"Adding LED with pins {pins}") if isinstance(pins, int): self.leds[name] = LED(pins) else: self.leds[name] = RGBLED(*pins, initial_value=(.7, 1, 1))
class DoorbellAlarm: led = RGBLED(red=17, green=22, blue=27) buzzer = Buzzer(26) num_of_times = 0 def __init__(self, num_of_times): self.num_of_times = num_of_times def play_sequence(self): num = 0 while num < self.num_of_times: self.buzzer.on() self.light_show() sleep(0.5) self.buzzer.off() sleep(0.5) num += 1 def light_show(self): self.led.color = (1, 0, 0) sleep(0.1) self.led.color = (0, 1, 0) sleep(0.1) self.led.color = (0, 0, 1) sleep(0.1) self.led.off()
def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) red_pin = int(os.getenv('RED_PIN')) green_pin = int(os.getenv('GREEN_PIN')) blue_pin = int(os.getenv('BLUE_PIN')) self.led = RGBLED(red=red_pin, green=green_pin, blue=blue_pin) self.setLedColor()
def __init__(self): self.led = RGBLED(self.PIN_RED, self.PIN_GREEN, self.PIN_BLUE) self.led.value = (1,1,0) self.relay = LED(self.PIN_RELAY) # Create TFT LCD display class. self.disp = TFT.ST7789(self.PIN_DC, rst=self.PIN_RST, \ spi=SPI.SpiDev(self.SPI_PORT, self.SPI_DEVICE, \ max_speed_hz=64000000)) # Initialize display. self.disp.begin() # Clear the display to a red background. # Can pass any tuple of blue, green, red values (from 0 to 255 each). self.disp.clear((255, 0, 0)) # Initialize blackbean database class self.bbdb = bbsql.bbdb(self.DATAPATH, self.DATABASE) # Initialize PN532 RFID class self.bbsc = bbscan.bbscan() print(self.bbsc.resp) # Initialize encryption class self.bbenc = bbenc.bbenc() self.bbenc.load_public() print(self.bbenc.resp)
def __init__(self, red, green, blue): """ sets up the Interface Args: red (int): GPIO Pin green (int): GPIO pin blue (int): GPIO Pin """ self._led_strip = RGBLED(red, green, blue) self._cur_color = "#0000FF" self._prev_color = "#0000FF" self._is_pulse = False self._defined_colors = { "none": "#000000", "red": "#FF0000", "green": "#00FF00", "blue": "#0000FF", "purple": "#FF00FF", "yellow": "#FFFF00", "aqua": "#00FFFF", "orange": "#FF1000", "magenta": "#FF0080", "white": "#FFFFFF" }
def init_rgb(self, red_pin, grn_pin, blu_pin): try: self.deinit_rgb() self.led = RGBLED(red=red_pin, green=grn_pin, blue=blu_pin, active_high=True, pin_factory=self.pin_factory) self._logger.info("LEDs initialized with pin factory: " + str(self.led.pin_factory)) except: self._logger.error("Error occurred while initializing LEDs")
def __init__(self, color, pins): # Unpack the pin values r_pin, g_pin, b_pin = pins # Init the RGB LED object, we will be using pwm and the color pins of # out LED are set to LOW self.led = RGBLED(r_pin, g_pin, b_pin, active_high=True, pwm=True) self.setColor(color)
def __init__(self): # self.__teapot = DigitalOutputDevice(PIN_TEAPOT, active_high=False) # self.__light = DigitalOutputDevice(PIN_LIGHT, active_high=False) # self.__amp = DigitalOutputDevice(PIN_AMP, active_high=False) self.__temp = ds18b20.DS18B20() self.__led = RGBLED(PIN_LED_R, PIN_LED_G, PIN_LED_B)
def __init__(self, red, green, blue, hw_relay, ch_relay, hw_button, ch_button, rgb_active_high, ch_relay_active_high, hw_relay_active_high): # Setup push buttons self.ch_button = BetterButton(ch_button, self.chPressed, self.BUTTON_BOUNCE_TIME, None, True) self.hw_button = BetterButton(hw_button, self.hwPressed, self.BUTTON_BOUNCE_TIME, None, True) # Setup relay self.hw_relay = DigitalOutputDevice(hw_relay, hw_relay_active_high) self.ch_relay = DigitalOutputDevice(ch_relay, ch_relay_active_high) # Setup RGB status LED self.status_led = RGBLED(red, green, blue, active_high=rgb_active_high) self.commands_file_path = config["commands_path"] self.schedule_file_path = config["schedule_path"] # Setup HW boost objects self.hw_boost_start = None self.ch_boost_on = False self.hw_pressed_flag = False self.ch_pressed_flag = False # Load first state self.state = IdleState(self) self.state.enter() # self.last_gateway_ping = datetime.now()
def __init__(self): #movement variables self.legs = Robot(left=(5, 6), right=(17, 27)) self.turning_right = False self.turning_left = False self.moving_forward = False self.moving_backward = False #used when preforming specific actions for fleeing Darth Vader self.turning_around = False self.time_turning_around = 0 self.running_away = False self.time_running_away = 0 self.fleeing = False #used to blink red-blue light self.light = RGBLED(red=16, green=20, blue=21) self.light.color = (1, 0, 0) self.red = True self.time_since_last_blink = 0 #used to make random movements self.time_stopped = 0 self.time_moving = 0 self.moving = False #used for reaction to characters self.seeing_Leia = False self.seen_Leia = False self.time_seeing_Leia = 0 self.seeing_Obiwan = False self.time_seeing_Obiwan = 0 self.seeing_Vader = False self.time_seeing_Vader = 0
def __init__(self, button_pin, button_func, red_pin, green_pin, blue_pin, cathode=False): self.led = RGBLED(red=red_pin, green=green_pin, blue=blue_pin, active_high=cathode) self.button = Button(button_pin, bounce_time=0.1) self.button.when_pressed = button_func
def __init__(self): logging.info("Beacon service initialized") with open(os.path.join(launchDir, 'beacon.json')) as data_file: self.configData = json.load(data_file) #need to account for no json data loaded if (self.configData.get("gpio")): gpioData = self.configData["gpio"] if gpioData.get("button"): self.button = Button(int(gpioData["button"])) self.button.when_released = self.buttonReleased self.button.when_held = self.buttonHeld else: logging.error( "config json gpio object missing required button id") if gpioData.get("red_led") and gpioData.get( "green_led") and gpioData.get("blue_led"): self.rgbLED = RGBLED(int(gpioData["red_led"]), int(gpioData["green_led"]), int(gpioData["blue_led"]), False, (0, 0, 0), True) else: logging.error( "config json gpio object missing required redled, greenled, and blueled ids" ) else: logging.error("config json missing require gpio object") if self.configData.get("directories"): dirObj = self.configData["directories"] if dirObj.get("sound"): soundDir = dirObj["sound"] if self.configData.get("commands"): self.commandsData = self.configData["commands"] self.ledDisplay(LedDisplayRule(0, 1, 0, 1, 1)) sleep(1) self.client = MQTTClient(self.configData["credentials"]["username"], self.configData["credentials"]["key"]) self.client.on_connect = self.connected self.client.on_disconnect = self.disconnected self.client.on_message = self.message while True: if self.connectState == ConnectState.Disconnected: self.connect() elif self.connectState == ConnectState.PendingReconnect: self.reconnect() try: self.client.loop() except RuntimeError: logging.exception("runtime error caught from mqtt client loop") self.reconnect()
def assign_led(self, led_pins): self._close_led() try: self._led = RGBLED(red=led_pins.get('red'), green=led_pins.get('green'), blue=led_pins.get('blue')) except PinInvalidPin: pass
def __init__(self, name, arrival_time, red, green, blue): self.name = name self.arrival_time = arrival_time self.light = RGBLED(red, green, blue) self.colors = { 'red': (1, 0, 0), 'blue': (0, 0, 1), 'green': (0, 1, 0), 'yellow': (1, 1, 0), }
def __init__(self): # set PINs on BOARD log.debug("Initializing LEDs...") log.debug("> RED pin: " + str(_conf['red_pin'])) log.debug("> GREEN pin: " + str(_conf['green_pin'])) log.debug("> BLUE pin: " + str(_conf['blue_pin'])) self.rgbled = RGBLED(_conf['red_pin'], _conf['green_pin'], _conf['blue_pin']) log.debug("...init done!")
def __init__(self, red, green, blue, verbose=False): self.led = RGBLED(red, green, blue) self.bright = 1 self.thread = Thread() self.stop_thread = False self.verbose = verbose if AUTODIM: t = Thread(target=self.autoDimming, daemon=True) t.start() self.changeLights(LightChanges.instant, DEFAULT_COLOR) self.dprint('lights init')
def run(): global R global G global B led = RGBLED(4, 17, 27) ldr = LightSensor(22, 50) R = (1, 0, 0) G = (0, 1, 0) B = (0, 0, 1) N = (0, 0, 0) Y = (1, 1, 0) # W = (1,1,1) # M = (1,0,1) night_time on_time = 0.01 on_time_noacft = 0.20 server_address = ('localhost', 30003) BUFF_LEN = 256 connCnt = 0 x = threading.Thread(target=thread_function, args=(1, ldr)) x.start() # INIT LED - Blink BLUE while not connected & data led.blink(0.25, 0.25, 0, 0, B, N) connect(server_address, ldr) try: while (1): data = sock.recv(BUFF_LEN) if (len(data) > 10): led.blink(on_time, 0, 0, 0, G, N, 1) else: led.blink(on_time, 0, 0, 0, R, N, 1) if not data: led.color = R connCnt = connCnt + 1 if (connCnt > 10): l('Error. Try to reconnect .... ') close() # No blink thread = block script for 20sec = time to SDR recovery led.blink(1, 1, 0, 0, Y, N, 10, False) led.blink(0.25, 0.25, 0, 0, B, N) connect(server_address, ldr) else: connCnt = 0 finally: led.color = N close()
def __init__(self, name, buttons, led): self.name = name self.buttons = [ self._create_button(index, pin) for index, pin in enumerate(buttons) ] self.led = RGBLED(*led, pwm=False) self.wins = 0 self.presses = [] self.elapsed_times = [] self.lock = Lock()
def __init__(self, level='lvl0'): #instantiating all the motors and sensors on the bot self.robot = Robot(left=MOTOR_L, right=MOTOR_R) self.sonic = DistanceSensor(echo=SONIC_ECHO, trigger=SONIC_TRIG) self.ir_l = MCP3008(IR_L) self.ir_r = MCP3008(IR_R) self.button = MCP3008(BTN) self.bz = TonalBuzzer(BZ) self.led = RGBLED(R, G, B) #creating custom variables self.speed = self.get_speed(level)
def notify_led(): """ blink LED indefinitely """ led = RGBLED(red=17, green=27, blue=22) while True: led.color = (1, 0, 1) time.sleep(1) led.off() time.sleep(1) led.color = (1, 1, 0) time.sleep(1)
def run(): options = { "a": { "indicator": LED(PIN_LED_A), "button": Button(PIN_BUTTON_A) }, "b": { "indicator": LED(PIN_LED_B), "button": Button(PIN_BUTTON_B) } } main = Main(options, RGBLED(*PIN_RGBLED)) pause()
def __init__(self, args): if args.test or args.replay: self.radio = None else: r = self.radio = rf95.RF95(cs=RF95_SPI_CS, int_pin=RF95_IRQ_PIN, reset_pin=RF95_RESET_PIN) assert r.init(), "failed to intialize radio" r.set_modem_config(rf95.Bw125Cr45Sf128) r.set_frequency(RF95_FREQ) self._args = args self.log_handle = open(args.log, 'w') if args.log else None self.replay_handle = open(args.replay, 'r') if args.replay else None self._pending_line = None self._time_offset = 0 if self.replay_handle: if self.read_replay_line(): self._time_offset = time.time() - self._pending_line[0] self.test = args.test self.use_tts = args.tts self.use_alarm = args.alarm self.numbers = args.phone self.emails = args.email self.stopping = False self.led = RGBLED(*RGBLED_PINS) self.lcd_thread = LCDThread(SEGMENT_PINS, DIGIT_PINS) self.trouble_tags = set() self.known_tags = set() self.monitor_thread = BackgroundThread(self.status_loop, start=False) self.announce_thread = None self._buzzer = False if twilio is not None: self.twilio_client = TwilioClient(TWILIO_SID, TWILIO_AUTH) else: self.twilio_client = None if sendgrid is not None: self.mail_client = sendgrid.SendGridAPIClient(apikey=SENDGRID_API_KEY) else: self.mail_client = None self.conn = None self.states = StateTracker()
def main(api_key, lat, long): # log in home dir logging.basicConfig( filename=PurePath(Path.home()).joinpath('logs/cloud.log'), level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') pi_led = RGBLED(red=17, green=27, blue=24, pin_factory=PiGPIOFactory()) darksky = DarkSky(api_key) forecast = darksky.get_forecast( lat, long, exclude=['minutely', 'hourly', 'daily', 'alerts', 'flags']).currently.icon logging.info('Icon: {}'.format(forecast)) weather_indicator(pi_led, WEATHER_COLOR_MAP.get(forecast, 'unknown_icon'))
def __init__(self): #movement variables self.legs = Robot(left=(5, 6), right=(17, 27)) self.turning_right = False self.turning_left = False self.moving_forward = False self.moving_backward = False #light variables #used to blink red-blue light self.light = RGBLED(red=16, green=20, blue=21) self.light.color = (1, 0, 0) self.red = True self.time_since_last_blink = 0
def __init__(self, red=RED_PIN, green=GREEN_PIN, blue=BLUE_PIN, white=WHITE_PIN): """ Initializer with default pins for each color. """ # This next line or two requires a version of gpiozero newer # than May 8 2016, which was when something happened. # Without this, it will complain about the pins # not supporting pwm. We also don't want to disable pwm, # because that prevents us from setting the brightness. self.rgb = RGBLED(red=red, green=green, blue=blue) self.white = PWMLED(white)
def run(): def set_led_color(): led.color = Color(*colors_list.values) def change_led_color(): colors_list.shuffle() set_led_color() led = RGBLED(PIN_RED, PIN_GREEN, PIN_BLUE) button = Button(PIN_BUTTON) colors_list = RandomList(3, MIN_VALUE, MAX_VALUE) set_led_color() button.when_pressed = change_led_color pause()
def __init__(self, callbPush, callbHang, ledPins=(17, 27, 22), buzzerPin=13, pttPin=18, canPin=19): # define properties self.led = RGBLED(ledPins[0], ledPins[1], ledPins[2]) self.buzzer = Buzzer(buzzerPin, active_high=True) self.pttButton = Device.pin_factory.pin(pttPin) self.canButton: Pin = Device.pin_factory.pin(canPin) # configure hardware self.__configPinHandler__(self.pttButton, self.__pttCallback__) self.__configPinHandler__(self.canButton, self.__canCallback__) self.cbCan = callbHang self.cbPtt = callbPush
def handle_lighting(): """Handles the lighting state management.""" status_led = RGBLED(13, 19, 26) steps = 100 current_step = 0 while not QUIT_EVENT.is_set(): if GPS_STATUS in GPSStatus.locked_states(): set_rgb_colour(status_led, Colour.GREEN) sleep(1) else: current_step = (current_step + 1) % steps cycle_rgb_led(status_led, current_step, steps) sleep(1 / steps) status_led.off() status_led.close()
def __init__(self, red_pin=18, green_pin=23, blue_pin=24, common_cathod=True): self.rgb_led = RGBLED( red_pin, green_pin, blue_pin, initial_value=(RGB.DEFAULT_RED, RGB.DEFAULT_GREEN, RGB.DEFAULT_BLUE), active_high= common_cathod # If you're using common anode. Otherwise, set this to false. ) self.running = False self.rgb_led.color = (RGB.DEFAULT_RED / 100.0, RGB.DEFAULT_GREEN / 100.0, RGB.DEFAULT_BLUE / 100.0)