def GetResult(owpin): for i in range(10): SH = 0 SL = 0 TH = 0 TL = 0 C = 0 data = getval(owpin) if len(data) == 40: humidity_bit = data[0:8] humidity_point_bit = data[8:16] temperature_bit = data[16:24] temperature_point_bit = data[24:32] check_bit = data[32:40] for i in range(8): #计算每一位的状态,每个字8位,以此为湿度整数,湿度小数,温度整数,温度小数,校验和 SH += humidity_bit[i] * 2**(7 - i) SL += humidity_point_bit[i] * 2**(7 - i) TH += temperature_bit[i] * 2**(7 - i) TL += temperature_point_bit[i] * 2**(7 - i) C += check_bit[i] * 2**(7 - i) if ((SH + SL + TH + TL) % 256) == C: break else: print("Read Sucess,But checksum error! retrying") gpio.delay(500) return SH, SL, TH, TL
def Move(self, com, val=0): wpi.digitalWrite(M_SETUP, HIGH) if com == "R_FW": wpi.softPwmWrite(R_IN1, val) wpi.softPwmWrite(R_IN2, 0) elif com == "R_RW": wpi.softPwmWrite(R_IN1, 0) wpi.softPwmWrite(R_IN2, val) elif com == "L_FW": wpi.softPwmWrite(L_IN1, val) wpi.softPwmWrite(L_IN2, 0) elif com == "L_RW": wpi.softPwmWrite(L_IN1, 0) wpi.softPwmWrite(L_IN2, val) elif com == "R_STOP": wpi.softPwmWrite(R_IN1, 0) wpi.softPwmWrite(R_IN2, 0) elif com == "L_STOP": wpi.softPwmWrite(L_IN1, 0) wpi.softPwmWrite(L_IN2, 0) elif com == "BRK": wpi.softPwmWrite(R_IN1, 100) wpi.softPwmWrite(R_IN2, 100) wpi.softPwmWrite(L_IN1, 100) wpi.softPwmWrite(L_IN2, 100) wpi.delay(500) wpi.softPwmWrite(R_IN1, 0) wpi.softPwmWrite(R_IN2, 0) wpi.softPwmWrite(L_IN1, 0) wpi.softPwmWrite(L_IN2, 0) wpi.digitalWrite(M_SETUP, LOW)
def setup(): global rssi_timeout, currently_tx if HAMSHIELD_RST: wiringpi.pinMode(RESET_PIN, wiringpi.OUTPUT) wiringpi.digitalWrite(RESET_PIN, wiringpi.LOW) print("type any character and press enter to begin...") while (not inputAvailable()): pass inputFlush() if HAMSHIELD_RST: # if you're using a standard HamShield (not a Mini) # you have to let it out of reset wiringpi.digitalWrite(RESET_PIN, wiringpi.HIGH) wiringpi.delay(5) # wait for device to come up print("beginning radio setup") # initialize device radio.initialize() # verify connection --- this does the part of "initialize serial communication" print("Testing device connections...") if (radio.testConnection()): print("HamShield connection successful") else: print("HamShield connection failed") print("setting default Radio configuration") # set frequency print("changing frequency") radio.setSQOff() freq = 446000 radio.frequency(freq) # set to receive radio.setModeReceive() currently_tx = False print("config register is: ") print(radio.readCtlReg()) print(radio.readRSSI()) """ set to transmit radio.setModeTransmit() maybe set PA bias voltage print("configured for transmit") radio.setTxSourceMic() """ radio.setRfPower(0) print("ready") rssi_timeout = 0
def main(): init() reset() while True: # activates first relay wp.digitalWrite(RELAY0_PIN, wp.LOW) wp.delay(1000) # deativates first relay wp.digitalWrite(RELAY0_PIN, wp.HIGH) wp.delay(1000) # activates second relay wp.digitalWrite(RELAY1_PIN, wp.LOW) wp.delay(1000) # deactivates second relay wp.digitalWrite(RELAY1_PIN, wp.HIGH) wp.delay(1000) # activates both relays wp.digitalWrite(RELAY0_PIN, wp.LOW) wp.digitalWrite(RELAY1_PIN, wp.LOW) wp.delay(1000) reset()
def getval(self): tl = [] tb = [] wiringpi.wiringPiSetup() wiringpi.pinMode(self.owpin, 1) wiringpi.digitalWrite(self.owpin, 1) wiringpi.delay(1) wiringpi.digitalWrite(self.owpin, 0) wiringpi.delay(25) wiringpi.digitalWrite(self.owpin, 1) wiringpi.delayMicroseconds(20) wiringpi.pinMode(self.owpin, 0) while (wiringpi.digitalRead(self.owpin) == 1): pass for i in range(45): tc = wiringpi.micros() while (wiringpi.digitalRead(self.owpin) == 0): pass while (wiringpi.digitalRead(self.owpin) == 1): if wiringpi.micros() - tc > 500: break if wiringpi.micros() - tc > 500: break tl.append(wiringpi.micros() - tc) tl = tl[1:] for i in tl: if i > 100: tb.append(1) else: tb.append(0) return tb
def controlMotor(value): wiringpi.softPwmWrite(IN1_PIN, value[0]) wiringpi.softPwmWrite(IN2_PIN, value[1]) wiringpi.softPwmWrite(IN3_PIN, value[2]) wiringpi.softPwmWrite(IN4_PIN, value[3]) print('control - %s\n' % value[4]) wiringpi.delay(30)
def printnumber(num_strs): num_strs = list(num_strs) # 1数字毎の処理 for num_str in num_strs: index = numbers[num_str] # 3,3V for i, x in enumerate(index): if x == 1: on_GPIO = A_GPIOs[i] pi.digitalWrite(on_GPIO, pi.HIGH) # 保持 pi.delay(500) # 0V for i, x in enumerate(index): if x == 1: on_GPIO = A_GPIOs[i] pi.digitalWrite(on_GPIO, pi.LOW) # 保持 pi.delay(100) # 出力をOUTPUT、0Vに初期化 for A_GPIO in A_GPIOs: pi.pinMode(A_GPIO, pi.INPUT)
def setup(): if HAMSHIELD_RST: wiringpi.pinMode(RESET_PIN, wiringpi.OUTPUT) wiringpi.digitalWrite(RESET_PIN, wiringpi.LOW) print("type any character and press enter to begin...") while (not inputAvailable()): pass inputFlush() if HAMSHIELD_RST: # if you're using a standard HamShield (not a Mini) # you have to let it out of reset wiringpi.digitalWrite(RESET_PIN, wiringpi.HIGH) wiringpi.delay(5) # wait for device to come up print("beginning radio setup") # initialize device radio.initialize() # verify connection --- this does the part of "initialize serial communication" print("Testing device connections...") if (radio.testConnection()): print("HamShield connection successful") else: print("HamShield connection failed") print("setting default Radio configuration") radio.setRfPower(0) radio.frequency(146520) radio.setModeReceive()
def reset(self): wiringpi.digitalWrite(SS_PIN, wiringpi.LOW) wiringpi.delayMicroseconds(10) wiringpi.digitalWrite(SS_PIN, wiringpi.HIGH) wiringpi.delayMicroseconds(40) self.spiStrobe(CC1101_SRES) wiringpi.delay(1)
def GetResult(owpin): for i in range(10): SH = 0 SL = 0 TH = 0 TL = 0 C = 0 result = getval(owpin) if len(result) == 40: for i in range(8): SH *= 2 SH += result[i] SL *= 2 SL += result[i + 8] TH *= 2 TH += result[i + 16] TL *= 2 TL += result[i + 24] C *= 2 C += result[i + 32] if ((SH + SL + TH + TL) % 256) == C and C != 0: break else: return broke_data, broke_data else: return broke_data, broke_data wiringpi.delay(200) return SH, TH
def GetResult(owpin): for i in range(10): #print("i=",i) SH = 0 SL = 0 TH = 0 TL = 0 C = 0 result = getval(owpin) #print("result-length=",len(result)) if len(result) == 40: for i in range(8): #计算每一位的状态,每个字8位,以此为湿度整数,湿度小数,温度整数,温度小数,校验和 SH *= 2 SH += result[i] SL *= 2 SL += result[i + 8] TH *= 2 TH += result[i + 16] TL *= 2 TL += result[i + 24] C *= 2 C += result[i + 32] if ((SH + SL + TH + TL) % 256) == C and C != 0: break else: print("Read Sucess,But checksum error! retrying") else: print("Read failer! Retrying") #print("delay start:") gpio.delay(200) #print("end") return SH, SL, TH, TL
def Sweep(servo, delay, st, ed): pin = servo for i in range(st, ed + 1, 1): wp.softPwmWrite(pin, i) wp.delay(delay) wp.delay(2000) '''
def setup_pi(): print("setup_pi started") wiringpi.wiringPiSetupGpio() for pins in byte1: wiringpi.pinMode(pins, 0) wiringpi.pullUpDnControl(pins, wiringpi.PUD_DOWN) # PUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP for pins in byte2: wiringpi.pinMode(pins, 0) wiringpi.pullUpDnControl(pins, wiringpi.PUD_DOWN) # PUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP wiringpi.pinMode(reset, 1) wiringpi.digitalWrite(reset, 0); #wiringpi.pinMode(rclk, 1) #wiringpi.digitalWrite(rclk, 0); for opins in byteSelect: wiringpi.pinMode(opins, 1) wiringpi.digitalWrite(opins, 1) wiringpi.pinMode(relay[0], 1) wiringpi.pinMode(relay[1], 1) wiringpi.digitalWrite(relay[0], 1); wiringpi.digitalWrite(relay[1], 1); wiringpi.digitalWrite(reset, 1); wiringpi.delay(1000) # Delay for 1000 useconds
def GetResult(self): gpio.delay(1000) for i in range(10): SH = 0 SL = 0 TH = 0 TL = 0 C = 0 result = self.getval() if len(result) == 40: for i in range(8): #计算每一位的状态,每个字8位,以此为湿度整数,湿度小数,温度整数,温度小数,校验和 SH *= 2 SH += result[i] SL *= 2 SL += result[i + 8] TH *= 2 TH += result[i + 16] TL *= 2 TL += result[i + 24] C *= 2 C += result[i + 32] if ((SH + SL + TH + TL) % 256) == C and C != 0: break else: print("Read Sucess,But checksum error! retrying") return 0.0, 0.0 else: print("Read failer! Retrying") return 0.0, 0.0 gpio.delay(200) temperture = TH + TL / 100 humidity = SH + SL / 100 print("湿度:", humidity, "温度:", temperture) return temperture, humidity
def safeExit(signum, frame): radio.setModeReceive() wiringpi.delay(25) if HAMSHIELD_RST: wiringpi.digitalWrite(RESET_PIN, wiringpi.LOW) wiringpi.delay(25) sys.exit(1)
def main(): plogger = init_logger('rasptea1.player') # init WiringPi wp.wiringPiSetup() # set pin 4 to input mode wp.pinMode(4, 0) # keep player status playerActive = False # infinite loop while True: try: # read sensor state motionState = wp.digitalRead(4) if motionState == 1 and not playerActive: player = subprocess.Popen( ['omxplayer', '-o', 'local', AUDIOFILE], stdout=subprocess.PIPE, stderr=subprocess.PIPE) plogger.info('Player started') playerActive = True # wait for audio played completely player.wait() plogger.info('Player stopped') playerActive = False except Exception as e: plogger.error('Player error in loop occured %s' % (e, )) # wait for 100 ms wp.delay(100)
def GetResult(owpin): for i in range(10): SH = 0 SL = 0 TH = 0 TL = 0 C = 0 result = getval(owpin) # print(len(result)) if len(result) == 40: for i in range(8): # 计算每一位的状态,每个字8位,以此为湿度整数,湿度小数,温度整数,温度小数,校验和 SH *= 2 SH += result[i] SL *= 2 SL += result[i + 8] TH *= 2 TH += result[i + 16] TL *= 2 TL += result[i + 24] C *= 2 C += result[i + 32] if ((SH + SL + TH + TL) % 256) == C and C != 0: break else: #print("Read Sucess,But checksum error! retrying") raise RuntimeError('Read Sucess,But checksum error! retrying') else: #print("Read failer! Retrying") raise RuntimeError('Read failer! Retrying') gpio.delay(200) return str(TH) + '.' + str(TL) + ',' + str(SH) + '.' + str(SL)
def beginControl(): setupPins() current_cmd = -1 while True: current_cmd = getch() if current_cmd == 'w': moveForward() elif current_cmd == 's': moveBackward() elif current_cmd == 'd': moveRight() elif current_cmd == 'a': moveLeft() elif current_cmd == 'q': rotateRight() elif current_cmd == 'e': rotateLeft() elif current_cmd == 'u': dispense() wp.delay(40) reset()
def GetResult(pin): for i in range(10): SH = 0 SL = 0 TH = 0 TL = 0 C = 0 result = getval(pin) if len(result) == 40: for i in range(8): SH *= 2 SH += result[i] # humi Integer SL *= 2 SL += result[i + 8] # humi decimal TH *= 2 TH += result[i + 16] # temp Integer TL *= 2 TL += result[i + 24] # temp decimal C *= 2 C += result[i + 32] # Checksum if ((SH + SL + TH + TL) % 256) == C and C != 0: break else: print("Read Sucess,But checksum error! retrying") else: print("Read failer! Retrying") break wiringpi.delay(200) return SH, SL, TH, TL
def readTemperature(self): max102 = self.max102 # Step 1: Config die temperature register to take 1 temperature sample max102.write_byte_data(self, self.MAX30102_ADDRESS, self.MAX30102_DIETEMPCONFIG, 0x01) # Poll for bit to clear, reading is then complete # Timeout after 100 ms startTime = wiry.millis() while wiry.millis() - startTime < 100: response = max102.read_byte_data(self.MAX30102_ADDRESS, self.MAX30102_DIETEMPCONFIG) if (response & 0x01) == 0: break wiry.delay(1) # if (millis() - startTime >= 100) return (-999) # Step 2: Read die temperature register (integer) tempInt = max102.read_byte_data(self, self.MAX30102_ADDRESS, self.MAX30102_DIETEMPCONFIG) tempFrac = max102.read_byte_data(self, self.MAX30102_ADDRESS, self.MAX30102_DIETEMPFRAC) # Step 3: Calculate temperature (datasheet pg. 22) return tempInt + tempFrac * 0.0625
def checksum(self): for i in range(10): SH = 0 SL = 0 TH = 0 TL = 0 C = 0 result = self.getval() if len(result) == 40: for i in range(8): SH *= 2 SH += result[i] SL *= 2 SL += result[i + 8] TH *= 2 TH += result[i + 16] TL *= 2 TL += result[i + 24] C *= 2 C += result[i + 32] if ((SH + SL + TH + TL) % 256) == C and C != 0: break else: print("Read Sucess,But checksum error! retrying") else: print("Read failer! Retrying") wiringpi.delay(200) return SH, SL, TH, TL
def loop(): # In milliseconds TRANSMITLENGTH = 60000 # In minutes INTERVAL = 10 RANDOMCHANCE = 3 # We'll wait up to 30 seconds for a a clear channel, # requiring that the channel is clear for 2 seconds before we transmit if radio.waitForChannel(30000, 2000, -90): # If we get here, the channel is clear. Let's print the RSSI as well print("Signal is cleaer, RSSI: ", radio.readRSSI()) # Set the HamShield to TX print("Transmitting...") radio.setModeTransmit() # Generate a 600Hz tone for TRANSMITLENGTH time wiringpi.tone( MIC_PIN, 700, TRANSMITLENGTH) ###TODO replacement for "tone" function?? wiringpi.delay(TRANSMITLENGTH) # Identify the transmitter radio.morseOut(" CALLSIGN FOXHUNT") # Set the HamShield back to RX radio.setModeReceive() print("Done.") # Wait for INTERVAL + some random minutes before transmitting again waitMinute(INTERVAL + random.randint(0, RANDOMCHANCE + 1))
def run(self): print(self.ontime) wiringpi.delay(self.ontime) print(self.ontime) # time.sleep(((self.ontime))) self.signal.emit('timer out') print(self.ontime) print('t')
def main(): LED_PIN = 7 pi.wiringPiSetupGpio() pi.pinMode(LED_PIN, pi.OUTPUT) pi.digitalWrite(LED_PIN, pi.HIGH) pi.delay(5000) pi.digitalWrite(LED_PIN, pi.LOW)
def Sweep(servo, delay): (pin) = servo for i in range(0, 20, 19): wp.softPwmWrite(pin, i) wp.delay(delay) for i in range(20, 0, -19): wp.softPwmWrite(pin, i) wp.delay(delay)
def poll(interval): while True: try: step() except: print "Exception - investigate..." pass wiringpi.delay(interval)
def turnLeft(): stop() wiringpi.softPwmWrite(WHEEL_1, FAST) wiringpi.softPwmWrite(WHEEL_2, 0) wiringpi.softPwmWrite(WHEEL_3, SLOW) wiringpi.softPwmWrite(WHEEL_4, 0) wiringpi.delay(200) stop()
def lcd_write(dc, data): wiringpi.digitalWrite(PIN_DC, dc) wiringpi.digitalWrite(PIN_SCE, LOW) wiringpi.delay(SLOW_DOWN) # wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data) slow_shift_out(PIN_SDIN, PIN_SCLK, data) wiringpi.digitalWrite(PIN_SCE, HIGH) wiringpi.delay(SLOW_DOWN)
def lcd_write(dc, data): wiringpi.digitalWrite(PIN_DC, dc) wiringpi.digitalWrite(PIN_SCE, LOW) wiringpi.delay(SLOW_DOWN) #wiringpi.shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data) slow_shift_out(PIN_SDIN, PIN_SCLK, data) wiringpi.digitalWrite(PIN_SCE, HIGH) wiringpi.delay(SLOW_DOWN)
def run(self): while True: self.__blink() for i in range(FPS): for x in range(DIGITS): wiringpi.delay(DELAY) char = ('%03u' % self.__aqi)[x] self.__display(char, x + 1)
def is_long_pushed(pin): count = 0 while count < 4: state = wp.digitalRead(pin) if state != 0: return False count = count + 1 wp.delay(250) return True
def work(): pin = 17 wiringpi.pinMode(pin,wiringpi.GPIO.OUTPUT) try: for i in range (0,3): wiringpi.digitalWrite(pin,wiringpi.GPIO.HIGH) wiringpi.delay(500) wiringpi.digitalWrite(pin,wiringpi.GPIO.LOW) wiringpi.delay(500) finally: wiringpi.digitalWrite(pin,wiringpi.GPIO.LOW)
def run(self): while 1: left_pwm = getPWM(self.jr.velocity_left_weel) if left_pwm > 0: if left_pwm < self.jr.MIN_SPEED: left_pwm = 0 elif left_pwm > 70: left_pwm = 70 wiringpi.softPwmWrite(self.jr.MOTOR_LEFT_F, left_pwm) wiringpi.softPwmWrite(self.jr.MOTOR_LEFT_B, 0) elif left_pwm < 0: if left_pwm > - self.jr.MIN_SPEED: left_pwm = 0 elif left_pwm < - 70: left_pwm = - 70 wiringpi.softPwmWrite(self.jr.MOTOR_LEFT_F, 0) wiringpi.softPwmWrite(self.jr.MOTOR_LEFT_B, -left_pwm) else: wiringpi.softPwmWrite(self.jr.MOTOR_LEFT_F, 0) wiringpi.softPwmWrite(self.jr.MOTOR_LEFT_B, 0) right_pwm = getPWM(self.jr.velocity_right_weel) if right_pwm > 0: if right_pwm < self.jr.MIN_SPEED: right_pwm = 0 wiringpi.softPwmWrite(self.jr.MOTOR_RIGHT_F, right_pwm) wiringpi.softPwmWrite(self.jr.MOTOR_RIGHT_B, 0) elif right_pwm < 0: if right_pwm > - self.jr.MIN_SPEED: right_pwm = 0 wiringpi.softPwmWrite(self.jr.MOTOR_RIGHT_F, 0) wiringpi.softPwmWrite(self.jr.MOTOR_RIGHT_B, -right_pwm) else: wiringpi.softPwmWrite(self.jr.MOTOR_RIGHT_F, 0) wiringpi.softPwmWrite(self.jr.MOTOR_RIGHT_B, 0) wiringpi.delay(1) # 1 ms #print "self.jr.new_yaw_angle:,", self.jr.new_yaw_angle if self.jr.new_yaw_angle: if time.time() - self.jr.new_yaw_angle_arrived < self.jr.camera_motors_max_time: self.jr.yaw_motor_pwm.ChangeDutyCycle(self.jr.yawDegreeToDutyCycle(self.jr.yaw_angle)) else: self.jr.new_yaw_angle = False self.jr.yaw_motor_pwm.ChangeDutyCycle(0.0) if self.jr.new_pitch_angle: if time.time() - self.jr.new_pitch_angle_arrived < self.jr.camera_motors_max_time: self.jr.pitch_motor_pwm.ChangeDutyCycle(self.jr.pitchDegreeToDutyCycle(self.jr.pitch_angle)) else: self.jr.pitch_motor_pwm.ChangeDutyCycle(0.0) self.jr.new_pitch_angle = False
def fade(self, red, green, blue, delay=500, step=5): for i in range(0, delay, step): f = (0.0+i)/delay r = self.red + (red -self.red) * f wiringpi.softPwmWrite(self.r_pin, int(r)) g = self.green + (green-self.green) * f wiringpi.softPwmWrite(self.g_pin, int(g)) b = self.blue + (blue -self.blue) * f wiringpi.softPwmWrite(self.b_pin, int(b)) wiringpi.delay(step) self.red = red self.blue = blue self.green = green
def setupGyro(self): self.gy=wiringPiI2CSetup(ITG3200) if(self.gy == -1): print "Error al conectar con ITG3200" return -1 #Turning on the ITG3200 wiringPiI2CWriteReg8(self.gy, 0x3e, 0x00) wiringPiI2CWriteReg8(self.gy, 0x15, 0x07) wiringPiI2CWriteReg8(self.gy, 0x16, 0x1e) wiringPiI2CWriteReg8(self.gy, 0x17, 0x00) delay(10) self.gyroCalibrate()
def work(message): wiringpi.pinMode(PIN,wiringpi.GPIO.OUTPUT) for ch in message.upper(): if ch.isspace(): wiringpi.delay(SPACE) continue pattern = morsecode.MORSECODE.get(ch) print ("%s %s"%(ch, pattern)) if pattern is None: #Invalid character. Ignore continue else: signal(pattern) wiringpi.delay(INTERVAL)
def gyroCalibrate(self): tmpx=0 tmpy=0 tmpz=0 self.g_offx=0 self.g_offy=0 self.g_offz=0 for i in range(10): delay(10) gp=self.readGyro() tmpx=tmpx+gp[0] tmpy=tmpy+gp[1] tmpz=tmpz+gp[2] self.g_offx=tmpx/10 self.g_offy=tmpy/10 self.g_offz=tmpz/10
def lcd_initialise(): wiringpi.pinMode(PIN_BACKLIGHT, OUTPUT) wiringpi.digitalWrite(PIN_BACKLIGHT, HIGH) wiringpi.pinMode(PIN_SCE, OUTPUT) wiringpi.pinMode(PIN_RESET, OUTPUT) wiringpi.pinMode(PIN_DC, OUTPUT) wiringpi.pinMode(PIN_SDIN, OUTPUT) wiringpi.pinMode(PIN_SCLK, OUTPUT) wiringpi.digitalWrite(PIN_RESET, LOW) wiringpi.delay(SLOW_DOWN) wiringpi.digitalWrite(PIN_RESET, HIGH) wiringpi.delay(SLOW_DOWN) lcd_write(LCD_C, 0x21) # LCD Extended Commands. lcd_write(LCD_C, 0xCC) # Set LCD Vop (Contrast). lcd_write(LCD_C, 0x04) # Set Temp coefficent. //0x04 lcd_write(LCD_C, 0x14) # LCD bias mode 1:48. //0x13 lcd_write(LCD_C, 0x0C) # LCD in normal mode. lcd_write(LCD_C, 0x20) lcd_write(LCD_C, 0x0C)
def slow_shift_out(data_pin, clock_pin, data): for bit in bin(data).replace("0b", "").rjust(8, "0"): wiringpi.digitalWrite(clock_pin, LOW) wiringpi.delay(SLOW_DOWN) wiringpi.digitalWrite(data_pin, int(bit)) wiringpi.delay(SLOW_DOWN) wiringpi.digitalWrite(clock_pin, HIGH) wiringpi.delay(SLOW_DOWN)
def signal(pattern): for p in pattern: wiringpi.digitalWrite(PIN,wiringpi.GPIO.HIGH) if p == ".": wiringpi.delay(DOT) elif p == "-": wiringpi.delay(DASH) wiringpi.digitalWrite(PIN,wiringpi.GPIO.LOW) wiringpi.delay(INTERVAL)
wiringpi.digitalWrite(PIN_RESET, LOW) wiringpi.delay(SLOW_DOWN) wiringpi.digitalWrite(PIN_RESET, HIGH) wiringpi.delay(SLOW_DOWN) lcd_write(LCD_C, 0x21) # LCD Extended Commands. lcd_write(LCD_C, 0xCC) # Set LCD Vop (Contrast). lcd_write(LCD_C, 0x04) # Set Temp coefficent. //0x04 lcd_write(LCD_C, 0x14) # LCD bias mode 1:48. //0x13 lcd_write(LCD_C, 0x0C) # LCD in normal mode. lcd_write(LCD_C, 0x20) lcd_write(LCD_C, 0x0C) def lcd_clear(): for time in range(0, LCD_SEGS): lcd_write(LCD_D, 0x00) def lcd_fill(): for time in range(0, LCD_SEGS): lcd_write(LCD_D, 0xFF) lcd_initialise() for time in range(0, 4): lcd_clear() wiringpi.delay(1000) lcd_fill() wiringpi.delay(1000)
import wiringpi INPUT = 0 OUTPUT = 1 LOW = 0 HIGH = 1 BUTTONS = [13,12,10,11] LEDS = [0,1,2,3,4,5,6,7,8,9] PUD_UP = 2 wiringpi.wiringPiSetup() for button in BUTTONS: wiringpi.pinMode(button,INPUT) wiringpi.pullUpDnControl(button,PUD_UP) for led in LEDS: wiringpi.pinMode(led,OUTPUT) while 1: for index,button in enumerate(BUTTONS): button_state = wiringpi.digitalRead(button) first_led = LEDS[index*2] second_led = LEDS[(index*2)+1] #print str(button) + ' ' + str(button_state) wiringpi.digitalWrite(first_led,1-button_state) wiringpi.digitalWrite(second_led,1-button_state) wiringpi.delay(20)
# Pulsates an LED connected to GPIO pin 1 with a suitable resistor 4 times using softPwm # softPwm uses a fixed frequency import wiringpi OUTPUT = 1 PIN_TO_PWM = 1 wiringpi.wiringPiSetup() wiringpi.pinMode(PIN_TO_PWM,OUTPUT) wiringpi.softPwmCreate(PIN_TO_PWM,0,100) # Setup PWM using Pin, Initial Value and Range parameters for time in range(0,4): for brightness in range(0,100): # Going from 0 to 100 will give us full off to full on wiringpi.softPwmWrite(PIN_TO_PWM,brightness) # Change PWM duty cycle wiringpi.delay(10) # Delay for 0.2 seconds for brightness in reversed(range(0,100)): wiringpi.softPwmWrite(PIN_TO_PWM,brightness) wiringpi.delay(10)
# Demonstrates use of Arduino-like delay function import wiringpi print 'Hello World' wiringpi.delay(1500) # Delay for 1.5 seconds print 'Hi again!'
def millis(ms): wiringpi.delay(ms)
def motors(l, r): Config.motorL.speed(l) Config.motorR.speed(r) nunchuk.setup() try: while True: x,y = nunchuk.read_joy_normalized() r = nunchuk.clamp(math.sqrt(x*x + y*y), -8, 8) # It would perhaps be better if both motors were scaled by r when # x != 0. But this gives results which feel good, so there's no # particular need. if x == 0: motors(y*10, y*10) elif x < 0: if y >= 0: motors((y-4)*20, r*10) elif y < 0: motors(-r*10, (y+4)*20) elif x > 0: if y >= 0: motors(r*10, (y-4)*20) elif y < 0: motors((y+4)*20, -r*10) wiringpi.delay(int(1000/60)) except KeyboardInterrupt: motors(0, 0)