예제 #1
0
def lab_5():
    from gpiozero import Button # import module LED
    from gpiozero import LED # import module LED
    from time import sleep
    button = Button(2)
    led =LED(17)
    while True:
     if button.is_pressed:
     print("Pressed")
     led.on() # set the GPIO 17 to high
     else:
     print("Released")
     led.off() # set the GPIO 17 to low
     sleep(1)
    


from gpiozero import PWMLED
from time import sleep
led = PWMLED(21)
while True:
 led.value = 0 # off
 sleep(1)
 led.value = 0.5 # half brightness
 sleep(1)
 led.value = 1 # full brightness
 sleep(1)
    
if_name_=='_main_':
    lab_5()
def main():
	""" メイン関数 """
	# 接続ピン
	PIN_LD = 23
	PIN_PR = [ 10, 9, 11, 8 ]
	# フォトリフレクタ検出状態
	PR_STATE = [ 'Black', 'White' ]
	
	# 赤色LED設定
	red = LED(PIN_LD)
	# フォトリフレクタ(複数)設定(ボタンとして)
	photorefs = [ Button(PIN_PR[idx],active_state=True,pull_up=None) \
	for idx in range(0,len(PIN_PR)) ]
	
	# ループ処理
	while True:
		# 検出結果の初期化
		redflag = False
		# 検出結果の取得
		for idx in range(0,len(PIN_PR)):
			pr = photorefs[idx]
			bw = PR_STATE[pr.is_pressed]
			redflag = redflag or pr.is_pressed
			print('{}:{} '.format(idx+1,bw),end=' ')
		print()
		# 検出結果の論理和をLEDに出力 
		red.value = redflag
		# 0.1秒待機
		sleep(0.1)
예제 #3
0
def main():
    tlacitko = Button(21)
    ledka = LED(20)
    a = T()
    while True:
        c = tlacitko.value
        ledka.value = a.runT(c)[0]
        sleep(.001)  # například 0.05 sekundy
예제 #4
0
from time import sleep

from gpiozero import Button, LED
from DCBLP import T


t0 = T()
t1 = T()
t2 = T()
tlacitko = Button(21)  # v závorkách jsou čísla pinů
tlacitko2 = Button(19)
led1 = LED(20)
led2 = LED(16)
led3 = LED(26)
reset = 1
while True:
    reset = tlacitko2.value
    Y0 = t0.runTr(tlacitko.value, reset)[0]  # value vrací hodnotu tlačítka, pokud zmáčknuté tak je 1
    Y1 = t1.runTr(Y0, reset)[0]
    Y2 = t2.runTr(Y1, reset)[0]
    led1.value = Y2  # value u LED svítí, když je 1
    led2.value = Y1
    led3.value = Y0
    sleep(.02)
예제 #5
0
            output = process.communicate()[0]
            WHITE.value = 0
            print output
            speed_timer = speed_timer + 1
            print(position)
            if speed_timer < 3:
                time.sleep(1)
        else:
            WHITE.value = 0
            speed_timer = 0
            display.lcd_display_string(active_mode, 1)
            display.lcd_display_string("Press Up to Start", 2)

    elif active_mode == "Running":
        #RUNNING
        RED.value = 1
        display.lcd_clear()
        display.lcd_display_string("Three", 1)
        time.sleep(1)
        YELLOW.value = 1
        RED.value = 0
        display.lcd_clear()
        display.lcd_display_string("Two", 1)
        time.sleep(1)
        GREEN.value = 1
        YELLOW.value = 0
        display.lcd_clear()
        display.lcd_display_string("one", 1)
        time.sleep(1)

        #START RELAY
예제 #6
0
from gpiozero import LED
from time import sleep

rled = LED(26)
gled = LED(19)
gled.value = 1
red = LED(4)
blue = LED(18)
green = LED(22)
red.on()
blue.on()
green.on()
sleep(1)
gled.value = 0
rled.value = 1
red.off()
green.off()
blue.off()
rled.value = 0
예제 #7
0
try:
    BackdoorState = docs['backdoor']
    FrontdoorState = docs['frontdoor']
    WindowsState = docs['windows']
except:
    print("Device not regist")
# Lock Default

while True:

    try:
        BackdoorState = docs['backdoor']
        FrontdoorState = docs['frontdoor']
        WindowsState = docs['windows']
        if BackdoorState == False:
            LockBack.value = True
            UnlockBack.value = False
        elif BackdoorState == True:
            LockBack.value = False
            UnlockBack.value = True

        if FrontdoorState == False:
            LockFront.value = True
            UnlockFront.value = False
        elif FrontdoorState == True:
            LockFront.value = False
            UnlockFront.value = True

        if WindowsState == False:
            LockWindow.value = True
            UnlockWindow.value = False
예제 #8
0
from gpiozero import LED, Button
from time import sleep

led = LED(17)
button = Button(2)

while True:
    led.value = button.value
    sleep(0.01)
예제 #9
0
# Write your code here :-)

# gpiozero is a simple interface to GPIO devices with Raspberry Pi
from gpiozero import LED
import time

#   RPi Zero's pinouts Should be

#   RPI Signal  GPIO     PCB-to-Max7219# Python program to
#  print the binary value
# of the numbers from 1 to N

#   pin Name    Name    PCB pin
#   6   GND     Ground  1
#   19  DIN     GPIO10  2
#   24  CS      GPIO8   3
#   23  SCLK    GPIO11  4   Chip Select
#   2   5V      VCC     5

#
# 7219 commands are ('16-bit packet with 4-bit junk,
# 4-bit command and 8-bit data', bin(packet))

DIN = LED(19)
# input the value of n
n = int(input("Enter the value to send: "))

DIN.value = n
time.sleep(0.5)
print("n: ", bin(n))
print("DIN: ", bin(DIN.value))
예제 #10
0
파일: led_ex03.py 프로젝트: hongjy127/TIL
# 사용자의 입력을 받아 LED의 on/off 제어
# value를 사용해서

from gpiozero import LED

red = LED(21)

while True:
    x = input("LED on(1)/off(0) : ")
    if x == "q":
        break

    red.value = int(x)  # @property, 값을 대입하면 동작이 일어남
예제 #11
0
from gpiozero import Button, LED

from DCBLP import T

t0 = T()
t1 = T()
t2 = T()
tlacitko = Button(21)  # v závorkách jsou čísla pinů
tlacitko2 = Button(19)
led1 = LED(20)
led2 = LED(16)
led3 = LED(26)
cervena = LED(13)
tecko = T()
reset = 1
while True:
    Y0 = t0.runTr(
        tlacitko.value,
        reset)[0]  # value vrací hodnotu tlačítka, pokud zmáčknuté tak je 1
    Y1 = t1.runTr(Y0, reset)[0]
    Y2 = t2.runTr(Y1, reset)[0]
    led1.value = Y2  # value u LED svítí, když je 1
    led2.value = Y1
    led3.value = Y0
    reset = not (not Y2 and Y1 and not Y0)
    cervena.value = tecko.runT(not reset)[0]
    print(reset)
예제 #12
0
from gpiozero import LED
from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
engageSensor = LED(21)
engageSensor.on()
rled = LED(26)
gled = LED(19)
gled.value = 1
red = LED(4)
blue = LED(18)
green = LED(22)
red.on()
blue.on()
green.on()
while True:
  output = GPIO.input(20)
  if(output != 1):
    print(f"Stopping ${output}")
#    break
gled.value = 0
red.off()
green.off()
blue.off()
예제 #13
0
from gpiozero import LED
from gpiozero import Button

# this is how I've built my telescope handset
error_led = LED(4)

up_button = Button(7)
center_button = Button(12)
down_button = Button(16)
left_button = Button(20)
right_button = Button(21)

print "      ",

while True:
    up = up_button.value
    center = center_button.value
    down = down_button.value
    left = left_button.value
    right = right_button.value

    up_symbol = "U" if up else "-"
    center_symbol = "C" if center else "-"
    down_symbol = "D" if down else "-"
    left_symbol = "L" if left else "-"
    right_symbol = "R" if right else "-"

    print "\b\b\b\b\b\b" + up_symbol + center_symbol + down_symbol + left_symbol + right_symbol,

    error_led.value = up or center or down or left or right
예제 #14
0
import RPi.GPIO as GPIO  # Import Raspberry Pi GPIO library
from gpiozero import LED
from time import sleep
#LEDS
white = LED(06)
red = LED(13)
yellow = LED(19)
green = LED(26)
print("start")
white.value = 1
red.value = 1
yellow.value = 1
green.value = 1
sleep(1)
white.value = 0
red.value = 0
yellow.value = 0
green.value = 0
print("end")

#
예제 #15
0
        pass
    t2 = time.time()
    time.sleep(0.1)
    send_pin.on()
    time.sleep(0.1)
    return (t2 - t1) * 1000000


# This function takes 10 readings and finds the largest and puts it in the
# variable - threshold
def calibrate():
    global threshold
    print("Wait! Calibrating")
    n = 10
    maximum = 0
    for i in range(1, n):
        reading = step()
        if reading > maximum:
            maximum = reading
    threshold = maximum * 1.2
    print(threshold)
    print("Calibration Complete")


calibrate()

while True:
    reading = step()  # take a reading
    red_led.value = (reading > threshold
                     )  # LED on if reading > threshold, otherwise off
예제 #16
0
#pir1.when_motion = p_action(pin_pir1, "front: motion detected")
#pir2.when_motion = p_action(pin_pir2, "back: motion detected")



print("setting to: ",pi.set_servo_pulsewidth(servo_door_pin, 1500))
print("set to: ",pi.get_servo_pulsewidth(servo_door_pin))
temperature = 25.0
humidity = 73.0
temp_fan = False
ARMED = False
tt = 10.0
#fan.value = 1
#pi.stop()

slite.value = 1
sleep(3)
slite.value = 0

def getTemp():
    global temperature
    global humidity
    global tt
    hum, tempe = Adafruit_DHT.read_retry(sensormodel, sensorpin)
    humidity = hum
    humidity = float("{:0.2f}".format(humidity))
    temperature = tempe
    tt = tempe
    temperature  = float("{:0.2f}".format(temperature))

def p_action(client, message):
예제 #17
0
from gpiozero import Button, LED
from DCBLP import T

t0 = T()
t1 = T()
t2 = T()
t3 = T()

tlacitko = Button(21)  # v závorkách jsou čísla pinů
cervena = LED(13)
tecko = T()
reset = 1
while True:
    Y0 = t0.runTr(
        tlacitko.value,
        reset)[0]  # value vrací hodnotu tlačítka, pokud zmáčknuté tak je 1
    Y1 = t1.runTr(Y0, reset)[0]
    Y2 = t2.runTr(Y1, reset)[0]
    Y3 = t3.runTr(Y2, reset)[0]
    reset = not (not Y3 and Y2 and not Y1 and Y0)
    cervena.value = tecko.runT(not reset)[0]
    # False True False True
예제 #18
0
ir = DigitalInputDevice(16)

received = False
Mreceived = False
prevdirect = 'BACKWARD'
now = jarvis.get_current_datetime()
fetch_time = now - jarvis.datetime_offset(minutes=10)

while True:
    now = jarvis.get_current_datetime()

    L1_virtual = sp_server.get_thing_state_attributes(1571)
    RGB_virtual = sp_server.get_thing_state_attributes(1580)

    if (L1.value != L1_virtual.value):
        L1.value = L1_virtual.value
        received = True

    if B1.value == 1:
        L1.value = 1
        M1.forward()
        prevdirect = 'FORWARD'
        sp_server.update_thing_state_attributes(1573, value=B1.value)
        sp_server.update_thing_state_attributes(1571, value=L1.value)
        sp_server.update_thing_state_attributes(1575, direction='FORWARD')
        received = False
        Mreceived = False
    elif B1.value == 0 and received == False and Mreceived == False:
        L1.value = 0
        M1.backward()
        prevdirect = 'BACKWARD'
예제 #19
0
from gpiozero import LED, Button
from time import sleep
from datetime import datetime
from signal import pause

relay = LED(2)
button = Button(3)

while True:
    timestamp = datetime.now().isoformat()
    print(timestamp + ' : ' + str(button.value))
    sleep(1)
    relay.value = button.value


예제 #20
0
from time import sleep
import RPi.GPIO as GPIO
from gpiozero import LED

GPIO.setmode(GPIO.BCM)
TRACK_STEP = LED(20)  # Step GPIO Pin
TRACK_DIR = LED(21)   # Direction GPIO Pin
CW = 1     # Clockwise Rotation
CCW = 0    # Counterclockwise Rotation
speed = 0.1
distance = 200 #steps

for x in range(distance):
    TRACK_DIR.value = CCW
    TRACK_STEP.value = 1
    sleep(speed)
    TRACK_STEP.value = 0

for x in range(distance):
    TRACK_DIR.value = CW
    TRACK_STEP.value = 1
    sleep(speed)
    TRACK_STEP.value = 0
예제 #21
0
from gpiozero import LEDBoard, LED, Button, PWMLED
from time import sleep
import threading

graph = LEDBoard(12, 7, 23, 24)

enable = LED(19)  ####使能开关
enable.value = 1
xianwei_switch = Button(8)


def stop():
    graph.value = (0, 0, 0, 0)


def forward(delay, steps):
    for i in range(0, steps):
        graph.value = (0, 1, 0, 1)
        sleep(delay)
        graph.value = (0, 1, 1, 0)
        sleep(delay)
        graph.value = (1, 1, 0, 0)
        sleep(delay)
        graph.value = (1, 1, 0, 0)
        sleep(delay)


def backward(delay, steps):
    for i in range(0, steps):
        graph.value = (1, 0, 0, 1)
        sleep(delay)
예제 #22
0
'''
ledBathState = True
ledKitchState = True
ledBedState = True
'''

# Light Default 


while True:
    
    try:
      ledBathState = docs['bathroom']
      ledKitchState = docs['kitchen']
      ledBedState = docs['bedroom']
      ledBathroom.value = ledBathState
      ledKitchen.value = ledKitchState
      ledBedroom.value = ledBedState
    
      print("Change!!")
      docs = doc_ref.get()
      docs = docs.to_dict()
      print("Done!!")
    except :
      print( "Device no register" )
     
    #ledBathState = input('Bathroom: ')
    #ledBathroom.value = ledBathState
    #ledKitchState = input('Kitchen: ')
    #ledKitchen.value = ledKitchState
    #ledBedState = input('Bedroom: ')