def foo_callback(self, path, args): wiringpi2.digitalWrite(args[0],1) #sleep(0.03) scaled = args[1] / 127.0 wiringpi2.delay(int(scaled*15 + 4)) # five is min, max is uhhh 20 ish? wiringpi2.digitalWrite(args[0],0) print("received message '%s' with arguments: %d, %d" % (path, args[0], args[1]))
def set_status(self, new_status): """ Set the state of the door to open or closed, if its not already in that state. Args: new_status: 0 for closed, 1 for open. Raises: IOError: File access issues """ if new_status == self.status: logging.debug("status is the same, skipping set_status to %u", new_status) return if new_status == 1: # open logging.info("door opening") else: logging.info("door closing") self.init_output() # low turns the motor on wiringpi.digitalWrite(self.write_bcm_pin, 0) # this is simply to wait for the motor to finish running # we can't tell if its really finished so this sleep is just a guess # TODO while loop until read_bcm_pin is ready? sleep(10) # high turns the motor back off so that it can run again later wiringpi.digitalWrite(self.write_bcm_pin, 1) self.status = int(new_status)
def deactivate(self, pin): """ De-activate a pin """ if settings.count_from_right: pin = pin else: pin = 7 - pin wp.digitalWrite(pin, 0)
def switch(self, v): if self.reading() != v: self.logger.debug('relay: switch: pin:%s %s' % (self.pin, str(v))) wiringpi.pinMode(self.pin, v) wiringpi.digitalWrite(self.pin, v) else: self.logger.debug('relay: switch: pin %s ignore already %s' % (self.pin, str(v)))
def measure(): wiringpi2.digitalWrite(TRIG, 1) time.sleep(0.00001) wiringpi2.digitalWrite(TRIG, 0) pulse_start = time.time() while wiringpi2.digitalRead(ECHO)==0: pulse_start = time.time() # Once a signal is received, the value changes from low (0) to high (1), # and the signal will remain high for the duration of the echo pulse. # We therefore also need the last high timestamp for ECHO (pulse_end). pulse_end = time.time() while wiringpi2.digitalRead(ECHO) == 1: pulse_end = time.time() # We can now calculate the difference between the two recorded # timestamps, and hence the duration of pulse (pulse_duration). pulse_duration = pulse_end - pulse_start distance = pulse_duration * 17150 return distance
def _flash_led(self,nflash=1,delay=0.1): #nflash is the number of blink the led will make for n in range(nflash): gpio.digitalWrite(self.led,True) rospy.sleep(delay) gpio.digitalWrite(self.led,False) rospy.sleep(delay)
def resetPins(): global dest_conf for key, value in dest_conf.id_tree.items(): pin = value['gpio_pin'] wiringpi.digitalWrite(pin, 1) #lightbox support wiringpi.digitalWrite(config.BUSY_PIN, 1)
def runMotor(duration, direction): global activeTimer, startTime, lastDirection print("Running the motor for " + str(duration) + " seconds in direction " + str(direction)) sys.stdout.flush() # turn off any active timers if activeTimer: activeTimer.cancel() # set direction first. wpi.digitalWrite(coverDirectionPin, direction) # set the cover to be controlled by the Odroid wpi.digitalWrite(coverModePin, coverModeAutomatic) startTime = int(round(time.time() * 1000)) #time in ms print("Starting motor") sys.stdout.flush() # tell the caller we're opening/closing if direction: client.publish('ha/blind_cover/get', "opening", 0, False) else: client.publish('ha/blind_cover/get', "closing", 0, False) # start a thread to wait for the operation to complete and schedule a timer to finish it. lastDirection = direction if duration == coverOperationTime: # full run up or down if direction: activeTimer = threading.Timer(duration, stopBlinds, ["open"]) else: activeTimer = threading.Timer(duration, stopBlinds, ["closed"]) else: # partial control - we don't know the final position of the blinds activeTimer = threading.Timer(duration, stopBlinds, ["unknown"]) activeTimer.start()
def pin_on(dest_id): global dest_conf for key, value in dest_conf.id_tree.items(): pin = value['gpio_pin'] wiringpi.digitalWrite(pin, key != dest_id) #lightbox support wiringpi.digitalWrite(config.BUSY_PIN, 0)
def initialize(): # Initialize wiringpi wiringpi.wiringPiSetup() wiringpi.mcp23017Setup(PIN_BASE, I2C_ADDR) for button in BUTTONS: wiringpi.pinMode(PIN_BASE + button, OUTPUT) wiringpi.digitalWrite(PIN_BASE + button, ON)
def cleanup(): global camera wiringpi2.digitalWrite(LASER_EN_PIN, 0) #TODO:re-enable? disabled for now so we don't lose our pin configuration # unexport_pins() if camera: camera.close()
def startWatering(duration): delta = datetime.datetime.now() + timedelta(seconds=duration) logging.debug("Start Watering") logging.debug("Start Stop Watering at: " + delta.ctime()) wiringpi.digitalWrite(waterpin, 1) # Write 1 ( HIGH ) to pin 6 # set timer to stop watering scheduler.add_job(stopWatering, trigger="date", run_date=delta)
def initPorts(): # # define constants # INPUT = 0 OUTPUT = 1 PUD_UP = 2 # # use Broadcom GPIO pin scheme # gpio.wiringPiSetupGpio() # comparator output is PGOOD - needs pull-up # gpio.pinMode(PGOOD,INPUT) gpio.pullUpDnControl(PGOOD,PUD_UP) # # gpio.pinMode(CSb,OUTPUT) gpio.pinMode(UDb,OUTPUT) # # cs* -> 1 to deselect; USb is don't care # gpio.digitalWrite(CSb,1) return
def set_numbers(num_str): wiringpi.digitalWrite(7, 0) for x in range(71, -1, -1): wiringpi.digitalWrite(13, 0) wiringpi.digitalWrite(11, int(num_str[x])) wiringpi.digitalWrite(13, 1) wiringpi.digitalWrite(7, 1)
def _process_video(self, procClass, width=1296, heigth=730, depth=50, processors=4): gpio.digitalWrite(self.led, True) with sg.VAR_LOCK: #yuv : convert width and height to fit with yuv format sg._WIDTH = (width + 31) // 32 * 32 sg._HEIGTH = (heigth + 15) // 16 * 16 sg._DEPTH = depth sg.VIDEO_MATRIX = np.zeros([sg._DEPTH + 1, sg._HEIGTH, sg._WIDTH], np.uint8) sg.POOL = [procClass() for i in range(processors)] self.picam.resolution = (width, heigth) self.picam.framerate = 90 rospy.sleep(1) startTime = rospy.get_rostime() self.picam.capture_sequence(proc.streams(), 'yuv', use_video_port=True) gpio.digitalWrite(self.led, False) deltaTime = rospy.get_rostime() - startTime fps = depth / deltaTime.to_sec() rospy.loginfo("Capture : " + str(fps) + " fps.") return fps
def set_state(self, state): self._On = state _state = 0 if state: _state = 1 if self.verbose: print str(self.ssr.name) + " digitalWrite: " + str( self.ssr.pin) + " " + str(_state) #save the state if self.ssr.state != _state: self.ssr.state = _state self.ssr.save() #reverse if needed if self.ssr.reverse_polarity and self.enabled: _state = not _state if wiringpi2_available: wiringpi2.digitalWrite(int(self.ssr.pin), _state) elif bbb_available: if _state: GPIO.output(self.ssr.pin, GPIO.HIGH) else: GPIO.output(self.ssr.pin, GPIO.LOW)
def set_status(self, new_status): """ Set the state of the door to open or closed, if its not already in that state. Args: new_status: 0 for closed, 1 for open. Raises: IOError: File access issues """ if new_status == self.status: logging.debug("status is the same, skipping set_status to %u", new_status) return if new_status == 1: #open logging.info("door opening") else: logging.info("door closing") self.init_output() # low turns the motor on wiringpi.digitalWrite(self.write_bcm_pin, 0) # this is simply to wait for the motor to finish running # we can't tell if its really finished so this sleep is just a guess # TODO while loop until read_bcm_pin is ready? sleep(10) # high turns the motor back off so that it can run again later wiringpi.digitalWrite(self.write_bcm_pin, 1) self.status = int(new_status)
def _write(self, status): if status: wiringpi2.digitalWrite(self.pin, 1) time.sleep(self.DELAY_LED) else: wiringpi2.digitalWrite(self.pin, 0) time.sleep(self.DELAY_LED)
def main(): connectDB() createDBtable() setPin() openBL() print BLwrite("AT") startInq() while 1: res = BLread() time.sleep(0.1) if "OK\r" in res: showDB() BLwrite("AT+INQ") else: if "+INQ" in res: res = parseInq(res) print res addToDB(res) # print BLwrite("AT+INQC") BLser.close() gpio.digitalWrite(1, 0)
def setFanSpeed(self): START = 650 # this value is minimal pwm value that can start the fan, depends on the fan and transistors used LO_TEMP = 45.0 # minimal temperature that turns on the fan HI_TEMP = 55.0 # when core temperature is higher than this the fan operates at full speed tempDiff = HI_TEMP - LO_TEMP temp = self.readtemp() if self.PWMmode: if temp < LO_TEMP: pwm = 0 elif temp > HI_TEMP: pwm = 1023 else: pwm = (1023-START)/tempDiff * temp - ((1023-START)/tempDiff)*LO_TEMP + START pwm = int(pwm) wiringpi2.pwmWrite(1, pwm) return pwm elif not self.PWMmode: if self.fanRunning: if temp <= LO_TEMP: wiringpi2.digitalWrite(1, 0) self.fanRunning = False return(0) else: return(1023) elif not self.fanRunning: if temp > HI_TEMP: wiringpi2.digitalWrite(1, 1) self.fanRunning = True return(1023) else: return(0)
def shutdown(self): try: for x in self.leds.pins: wiringpi2.digitalWrite(x, 0) self.cancel_pub.publish(GoalID()) except: pass
def beeper(beeps): "Beep all of the requested beeps in the beeps list" for i in beeps: wiringpi2.digitalWrite(1,1) # beep on time.sleep(i) # length of beep from beeps list wiringpi2.digitalWrite(1,0) # beep off time.sleep(0.025) # interval between beeps
def fancontrol(input): import wiringpi2 as wiringpi OUTPUT = 1 INPUT = 0 wiringpi.wiringPiSetup() wiringpi.pinMode(8,OUTPUT) wiringpi.digitalWrite(8,input)
def set_state(self, state): self._On = state _state = 0 if state: _state = 1 if self.verbose: print str(self.ssr.name) + " digitalWrite: " + str(self.ssr.pin) + " " + str(_state) #save the state if self.ssr.state != _state: self.ssr.state = _state self.ssr.save() #reverse if needed if self.ssr.reverse_polarity and self.enabled: _state = not _state if wiringpi2_available: wiringpi2.digitalWrite(int(self.ssr.pin), _state) elif bbb_available: if _state: GPIO.output(self.ssr.pin, GPIO.HIGH) else: GPIO.output(self.ssr.pin, GPIO.LOW)
def reset_leds(): # resets the leds after 5 secs global number number = 0 sleep(5) while number < 8: wiringpi.digitalWrite(int(number),0) number = number + 1
def dSPIN_init(): err = 0; err = wp.wiringPiSetupGpio(); wp.pinMode(hd.dSPIN_BUSYN, wp.GPIO.INPUT); wp.pinMode(hd.dSPIN_RESET, wp.GPIO.OUTPUT); wp.pinMode(hd.dSPIN_CS, wp.GPIO.OUTPUT); wp.digitalWrite(hd.dSPIN_CS, wp.GPIO.HIGH); if( err !=0): print("wiringPi Setup failed with Error"+err); return hd.dSPIN_STATUS_FATAL; wp.pinMode(hd.dSPIN_MOSI, wp.GPIO.OUTPUT); wp.pinMode(hd.dSPIN_MISO, wp.GPIO.INPUT); wp.pinMode(hd.dSPIN_CLK, wp.GPIO.OUTPUT); # //SPI_MODE3 (clock idle high, latch data on rising edge of clock) wp.digitalWrite(hd.dSPIN_CLK, wp.GPIO.HIGH); # // reset the dSPIN chip. This could also be accomplished by # // calling the "dSPIN_ResetDev()" function after SPI is initialized. wp.digitalWrite(hd.dSPIN_RESET, wp.GPIO.HIGH); wp.delay(2); wp.digitalWrite(hd.dSPIN_RESET, wp.GPIO.LOW); wp.delay(2); wp.digitalWrite(hd.dSPIN_RESET, wp.GPIO.HIGH); wp.delay(2); return 0;
def AllOff(): # this sets all address decoder address input pins (A0 - A2) to low # this does not, however, cause all address decorder output pins # to go low. To set all output pins (Y0 - Y7) to low, # you need to set E1-E2-E3 is a state OTHER than Low-Low-High for p in pins: wiringpi.digitalWrite(p, LOW)
def turn_180(): gpio.digitalWrite(5, 0) gpio.digitalWrite(6, 1) gpio.pwmWrite(12, 300) gpio.pwmWrite(13, 300) time.sleep(2) stop()
def __init__(self): wp.wiringPiSetup() #left 23017, for audio wp.mcp23017Setup( PB1,0x20) for pin in OUTPUT_PINS_1: wp.pinMode(pin,OUTPUT) for pin in INPUT_PINS_1: wp.pinMode(pin, INPUT) #right 23017 for 230v switching wp.mcp23017Setup( PB2,0x21) for pin in OUTPUT_PINS_2: wp.pinMode(pin,OUTPUT) for pin in INPUT_PINS_2: wp.pullUpDnControl(pin,PUD_UP) wp.pinMode(pin, INPUT) #display wp.digitalWrite(70,0) # write mode self.display1 = wp.lcdInit(2,16,8, 71,69,72,73,74,75,76,77,78,79) #connected to first expander wp.lcdClear(self.display1) #pwm driver self.pwm = PWM() self.pwm.setPWMFreq(200)
def initPorts(): # # define constants # INPUT = 0 OUTPUT = 1 PUD_UP = 2 # # use Broadcom GPIO pin scheme # gpio.wiringPiSetupGpio() # comparator output is PGOOD - needs pull-up # gpio.pinMode(PGOOD, INPUT) gpio.pullUpDnControl(PGOOD, PUD_UP) # # gpio.pinMode(CSb, OUTPUT) gpio.pinMode(UDb, OUTPUT) # # cs* -> 1 to deselect; USb is don't care # gpio.digitalWrite(CSb, 1) return
def is_dead(self): if self.lives < 0: GPIO.digitalWrite(pinFirstGameLost, 0) self.rounds_won = 0 self.refresh_screen() self.level_up = 50 self.explode = False self.alien_explode = False pygame.mixer.music.stop() self.screen.fill(BLACK) pygame.draw.rect( self.screen, RED, pygame.Rect(170, 210, self.screen.get_width() - (2 * 170), self.screen.get_height() - (2 * 210)), 10) text = self.game_font_medium.render("The war is lost!", 1, RED) self.screen.blit( text, (text.get_rect(centerx=self.screen.get_width() / 2).x, 240)) text = self.game_font_medium.render( "You scored: " + str(self.score), 1, RED) self.screen.blit( text, (text.get_rect(centerx=self.screen.get_width() / 2).x, 320)) pygame.display.update(160, 200, self.screen.get_width() - (2 * 160), self.screen.get_height() - (2 * 200)) pygame.time.delay(10000) return True
def set(self,newState): newState = int(newState) # FIXME need to catch error print "Switching relay " + `self.relayA` + " to " + `newState` wiringpi.pinMode(self.relayA,self.OUTPUT_MODE) initialState = wiringpi.digitalRead(self.relayA) wiringpi.digitalWrite(self.relayA, newState) currentState = wiringpi.digitalRead(self.relayA) result = None if(initialState == currentState): result = "Target state was already set. No action taken" else: result = "Switched" errors = None return { "controller": self.name, "timestamp": datetime.datetime.now().isoformat(' '), "result": result, "errors": errors, }
def test(): pin = 0 gpio.wiringPiSetup() #初始化 gpio.wiringPiSetupSys() #初始化 gpio.pinMode(pin, GPIO.OUTPUT) # 把pin25设置为输出模式 gpio.digitalWrite(pin, GPIO.HIGH) #pin25输出为高电平 print(gpio.digitalRead(pin)) #打印pin25的状态
def display_char(char, font=FONT): try: wiringpi.digitalWrite(DC, ON) spi.writebytes(font[char] + [0]) except KeyError: pass # Ignore undefined characters.
def display_char(char, font=FONT): try: wiringpi.digitalWrite(DC, ON) spi.writebytes(font[char]+[0]) except KeyError: pass # Ignore undefined characters.
def all_off(): for pin in pins_pol: w.digitalWrite(pin, 0) for pin in pins_pwm: w.softPwmWrite(pin,0) mag_value=[0,0,0,0]
def __init__(self, therm_pin, sensor_pin, target_temp=55): self.target_temp = target_temp self.THERM = therm_pin self.sensor = Sensor(sensor_pin) self.running = True self.heat_on = False self.current_temp = None self.OUT = 1 self.IN = 0 self.PWM = 0 self.bounds = [55, 66, 80] self.learner = learner.Events(self, 'therm', 55, 5, 5 * 60) self.set_lock = RLock() wiringpi.wiringPiSetupSys() setupInCmd1 = 'echo "{}" > /sys/class/gpio/export'.format(sensor_pin) setupOutCmd1 = 'echo "{}" > /sys/class/gpio/export'.format(self.THERM) setupInCmd2 = 'echo "in" > /sys/class/gpio/gpio{}/direction'.format(sensor_pin) setupOutCmd2 = 'echo "out" > /sys/class/gpio/gpio{}/direction'.format(self.THERM) Popen( setupInCmd1, shell=True) Popen( setupInCmd2, shell=True) Popen(setupOutCmd1, shell=True) Popen(setupOutCmd2, shell=True) wiringpi.pinMode(self.THERM, self.OUT) wiringpi.pinMode(sensor_pin, self.IN) wiringpi.digitalWrite(self.THERM, 0) # give some time to read an initial temperature self.timer = Timer(15, self.tick) self.timer.start() self.temp_log_timer = Timer(5 * 60, self.logTemp) self.temp_log_timer.start() self.temp_logger = jsonlog.jsonLog('data/real-therm-data')
def controlPin(self, onTime, offTime, pin): wp.pinMode(pin, 1) while not self.stop: wp.digitalWrite(pin, 1) time.sleep(onTime.value) wp.digitalWrite(pin, 0) time.sleep(offTime.value)
def setMux(n): mask = 1 for pin in range(0, 3): if (mask & n) != 0: io.digitalWrite(muxPins[pin], 1) else: io.digitalWrite(muxPins[pin], 0) mask = mask << 1
def _set(self, target_temp): self.target_temp = float(target_temp) if self.current_temp and self.current_temp < self.target_temp and not self.heat_on: self.heat_on = True wiringpi.digitalWrite(self.THERM, 1) elif self.current_temp > self.target_temp and self.heat_on: self.heat_on = False wiringpi.digitalWrite(self.THERM, 0)
def off(self): if self.timer: self.timer.cancel() if self.temp_log_timer: self.temp_log_timer.cancel() self.sensor.off() self.learner.off() wiringpi.digitalWrite(self.THERM, 0)
def setup(): wiringpi.wiringPiSetupGpio() wiringpi.pinMode(25,1) #red light wiringpi.digitalWrite(25,0) #red is off wiringpi.pinMode(24,1) #green light wiringpi.digitalWrite(24,0) #green is off flash(2)
def sequence(repeat): count = 0 while count <= repeat: for p in pins: wiringpi.digitalWrite(p, HIGH) sleep(count*.01) wiringpi.digitalWrite(p, LOW) count += 1
def _relayOff(self, pin): self._debugPrint("Relay {} Off".format(pin)) if pin == self._relayAIO: self._relayACanvas.itemconfigure(self._relayAimg, image=self._relayAPhotoimageLow) wiringpi2.digitalWrite(self._relayAIO, 0) elif pin == self._relayBIO: self._relayBCanvas.itemconfigure(self._relayBimg, image=self._relayBPhotoimageLow) wiringpi2.digitalWrite(self._relayBIO, 0)
def ledsBlink(): for times in range(20): for bitPos in range(3): wpi.digitalWrite(ledPin[bitPos], 1-wpi.digitalRead(switchPin[bitPos])) time.sleep(0.25) resetLeds() resetSwitch() time.sleep(0.25)
def setPin(): gpio.wiringPiSetup() gpio.pinMode(1, 1) gpio.digitalWrite(1, 0) time.sleep(0.3) gpio.digitalWrite(1, 1)
def control_heater(heater): global CURRENTSTATUE, TURNON, TURNOFF if(wiringpi.digitalRead(1) and heater): wiringpi.digitalWrite(0,1) CURRENTSTATUE=TURNON else: wiringpi.digitalWrite(0,0) CURRENTSTATUE=TURNOFF
def __init__(self, external_lights): super(Lights, self).__init__() self.external_lights = external_lights # hardware PWM led (and power off lights) wiringpi2.pinMode(self.LIGHTS_PIN, wiringpi2.GPIO.PWM_OUTPUT) wiringpi2.pwmWrite(self.LIGHTS_PIN, self.PWM_VAL_MAX) if self.external_lights: wiringpi2.pinMode(self.EXTERNAL_LIGHTS_PIN, wiringpi2.GPIO.OUTPUT) wiringpi2.digitalWrite(self.EXTERNAL_LIGHTS_PIN, 1)
def red(cls, state): if (state): #GPIO.output(cls._led_red_pin, GPIO.HIGH) #pigpio.write(cls._led_red_pin, pigpio.HIGH) wiringpi2.digitalWrite(cls._led_red_pin, wiringpi2.GPIO.HIGH) else: #GPIO.output(cls._led_red_pin, GPIO.LOW) #pigpio.write(cls._led_red_pin, pigpio.LOW) wiringpi2.digitalWrite(cls._led_red_pin, wiringpi2.GPIO.LOW)
def initRC(self,pin): #make pin output wp.pinMode(pin,1) #set pin to high to discharge capacitor wp.digitalWrite(pin,1) #wait 1 ms #time.sleep(0.1) #make pin Input wp.pinMode(pin,0)
def __init__(self, addr=0xE0E0E0E0E0, debug=False): self.addr = addr self.debug = debug; if debug: print("Initializing RF24 via /dev/spidev0.0") self.spi = spidev.SpiDev() self.spi.open(0,0) self.ce = 6 wpi.wiringPiSetup() wpi.pinMode(self.ce, wpi.GPIO.OUTPUT) wpi.digitalWrite(self.ce, 0) ## ## Config registers (most borrowed from Arduino RF24 lib defaults) ## # CONFIG :: Base configuration self.MASK_RX_DR = 1 self.MASK_TX_DS = 1 self.MASK_MAX_RT = 1 self.EN_CRC = 1 self.CRCO = 1 self.PWR_UP = 1 self.PRIM_RX = 1 self.write_config() #### Radio params (match the Arduino lib defaults) self.w_register(0x01, [0b00111111]) # EN_AA :: Auto-acknowledgement (on for all pipes) self.w_register(0x02, [0b00000000]) # EN_RXADDR :: Enabled RX pipes (disable all) self.w_register(0x03, [0b00000011]) # SETUP_AW :: Address space size (5 bytes) self.w_register(0x04, [0b00111111]) # SETUP_RETR :: TX retry behavior (1ms delay, 15 attempts) self.w_register(0x05, [76]) # RF_CH :: Frequency: 2400Mhz + (n * 1Mhz) self.w_register(0x06, [0b00000110]) # RF_SETUP :: Data rate & power (1 MBps, max power) self.w_register(0x07, [0b01110000]) # STATUS :: Various event flags (clear all) self.w_register(0x11, [0b00000000]) # RX_PW_P0 :: >>> self.w_register(0x12, [0b00000000]) # RX_PW_P1 :: >>>>> self.w_register(0x13, [0b00000000]) # RX_PW_P2 :: >>>>>>> Expected payload sizes for each self.w_register(0x14, [0b00000000]) # RX_PW_P3 :: >>>>>>> RX pipe (n/a, we're dynamic) self.w_register(0x15, [0b00000000]) # RX_PW_P4 :: >>>>> self.w_register(0x16, [0b00000000]) # RX_PW_P5 :: >>> self.w_register(0x1C, [0b00111111]) # DYNPD :: Dynamic payload (enable for all pipes) self.w_register(0x1D, [0b00000100]) # FEATURE :: Fancy bits (turn on dynamic payload sizing) ### ### Other housecleaning ### # Turn off all RX pipes for p in range(0,5): self.set_rx_pipeline(chan=p, enable=0) # Clear all resettable status bits. Clean slate! self.w_register(0x07, [0b01110000]) # Flush FIFOs self.flush_rx() self.flush_tx()
def winLED(player): for i in range(0, 4): # all LEDs off io.digitalWrite(ledPins[i], 1) if player == 0: # winner's LEDs yellow io.digitalWrite(ledPins[0], 0) io.digitalWrite(ledPins[1], 0) else: io.digitalWrite(ledPins[2], 0) io.digitalWrite(ledPins[3], 0)
def light(self, onoff): #print("Play " + filename) if self.lightstatus == onoff: print("NOP") return self.lightstatus = onoff self.last_play = time.time() value = "1" if onoff else "0" wiringpi.digitalWrite(0, (1 if onoff else 0))
def set_brightness(led_value): if LED == 1: if (0 <= led_value < 1023): wiringpi.pwmWrite(LED, led_value) else: if led_value == 0: wiringpi.digitalWrite(LED, OFF) else: wiringpi.digitalWrite(LED, ON)
def __init__(self, clk, dio): self.clk = clk self.dio = dio self.brightness = 0x0f pinMode(self.clk, GPIO.INPUT) pinMode(self.dio, GPIO.INPUT) digitalWrite(self.clk, GPIO.LOW) digitalWrite(self.dio, GPIO.LOW)
def processCommand(command): # if backlight is on, turn it off if command == 'toggleBacklight': if commandState['backlight']: wiringpi.digitalWrite(backlightPin, 1) commandState['backlight'] = False else: wiringpi.digitalWrite(backlightPin, 0) commandState['backlight'] = True
def activate(self, pin): """ Activate a pin """ if settings.count_from_right: pin = pin else: pin = 7 - pin if self.watchdog.watchdog_safe: wp.digitalWrite(pin, 1) else: wp.digitalWrite(pin, 0)
def Blink(A): LED = 2 #Associate pin ? to LED GPIO.pinMode(LED,1) #Set pin as GPIO out while True: GPIO.digitalWrite(LED, 1) #Set LED as HIGH time.sleep(1) #Wait for 1 second GPIO.digitalWrite(LED, 0) #Set LED as LOW time.sleep(1) #Wait for 1 second