示例#1
0
def buttonState():
    global showTimer
    global poweroffTimer
    global isDisplayCleared

    inputState = GPIO.input(PIN_BTN)
    if inputState == GPIO.HIGH:
        showTimer = 0
        isDisplayCleared = False
        poweroffTimer += UPDATE_DELAY
    else:
        poweroffTimer = 0

    if (poweroffTimer > POWEROFF_TIME):
        shutdown()

    return ()
示例#2
0
def my_callback(channel):
    print("Callback trigger %d" % channel)
    print("Now value of the Pin is %d" % (GPIO.input(PIN_NUM)))
    print("Click Ctr + C to exit")
示例#3
0
from __future__ import print_function
import NPi.GPIO as GPIO
import time

PIN_NUM = 12
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM, GPIO.IN, GPIO.PUD_DOWN)

print("The value of Pin %d is %d" % (PIN_NUM, GPIO.input(PIN_NUM)))


def my_callback(channel):
    print("Callback trigger %d" % channel)
    print("Now value of the Pin is %d" % (GPIO.input(PIN_NUM)))
    print("Click Ctr + C to exit")


GPIO.add_event_detect(PIN_NUM,
                      GPIO.RISING,
                      callback=my_callback,
                      bouncetime=300)

try:
    while True:
        time.sleep(0.1)
except KeyboardInterrupt:
    pass

GPIO.cleanup()
示例#4
0
time.sleep(1)

while True:
    try:
        pin = int(
            input(
                'Choose board pin number: \n( 3 - 24; excluded: 4, 6, 9, 14, 17, 20 )\n'
            ))
        mode = int(
            input('Choose pin state: \n( 0 - Low, 1 - High, 2 - Quit )\n'))
        print("\n\nChoosen %d (state %s)\n" % (mode, v_modes_str[mode]))
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, mode)
        time.sleep(0.5)
        print("Pin state changed!\n")
        #GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
        time.sleep(0.5)
        print("Now pin %d state is: %s\n" %
              (pin, v_modes_str[GPIO.input(pin)]))
        time.sleep(3)
    except ValueError:
        print("Not a number")
        continue
    except IndexError:
        if mode == 2:
            GPIO.cleanup()
            print("Bye :-(\n")
            break
        print("Not a valid pin or mode")
        continue
示例#5
0
def modetype(mode):
    for pin in range(range_pins[0], range_pins[1] + 1):
        if not pin in inv_pins:
            GPIO.setup(pin, GPIO.IN, pull_up_down=mode)
            print("value_%d = %d" % (pin, GPIO.input(pin)))
            time.sleep(0.1)
示例#6
0
#!/usr/bin/env python
from __future__ import print_function
import NPi.GPIO as GPIO
import time
from threading import Timer

PIN_NUM = 12
channel = 7
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.OUT)

GPIO.output(PIN_NUM,True)
print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM)))

GPIO.setup(channel,GPIO.IN,GPIO.PUD_DOWN)
print("\n value_%d = %d\n" %(channel,GPIO.input(channel)))


def makehigh():
    print("\n value_%d = %d\n" %(channel,GPIO.input(channel)))
    GPIO.output(PIN_NUM,False)
    print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM)))
    
    
GPIO.wait_for_edge(channel, GPIO.RISING)
t = Timer(1,makehigh)
t.start()
示例#7
0
def makehigh():
    print("\n value_%d = %d\n" %(channel,GPIO.input(channel)))
    GPIO.output(PIN_NUM,False)
    print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM)))
示例#8
0
#!/usr/bin/env python
from __future__ import print_function
import NPi.GPIO as GPIO
import time
from threading import Timer

SWITCH_PIN = 10
GPIO.setmode(GPIO.BOARD)
GPIO.setup(SWITCH_PIN, GPIO.IN, GPIO.PUD_DOWN)
print("\n value_%d = %d\n" % (SWITCH_PIN, GPIO.input(SWITCH_PIN)))

GPIO.add_event_detect(SWITCH_PIN, GPIO.RISING,
                      bouncetime=200)  # add rising edge detection on a channel

switchcount = 0
while switchcount < 2:
    if GPIO.event_detected(SWITCH_PIN):
        switchcount += 1
        print('Button pressed', switchcount)
        print("\n value_%d = %d\n" % (SWITCH_PIN, GPIO.input(SWITCH_PIN)))

GPIO.remove_event_detect(SWITCH_PIN)
示例#9
0
#!/usr/bin/env python
from __future__ import print_function
import NPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print("\n value_7 = %d\n" % (GPIO.input(7)))

GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("\n value_8 = %d\n" % (GPIO.input(8)))

GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print("\n value_12 = %d\n" % (GPIO.input(12)))
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("\n value_12 = %d\n" % (GPIO.input(12)))

#GPIO.cleanup()
示例#10
0
#!/usr/bin/env python
from __future__ import print_function
import NPi.GPIO as GPIO
import time
PIN_NUM = 8

GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.OUT)

GPIO.output(PIN_NUM,True)
print("\n value = %d\n" %(GPIO.input(PIN_NUM)))	
time.sleep(1)
GPIO.output(PIN_NUM,False)
print("\n value = %d\n" %(GPIO.input(PIN_NUM)))
time.sleep(1)

GPIO.cleanup()
示例#11
0
import NPi.GPIO as GPIO
import time

channel = 7

GPIO.setmode(GPIO.BOARD)
GPIO.setup(channel, GPIO.IN, GPIO.PUD_DOWN)
print(" Now input is Low\n Our task is performed when it becomes High")

while True:
    if GPIO.input(channel):
        print("Input was High,begin to perform")
        print("Count Down")
        for i in range(7, 0, -1):
            print("%d" % i)
            time.sleep(1)
        print("Performed!")
        exit()
示例#12
0
        # print(content[num_list_target - 1])
    except IOError :
        print('ERROR :'+IOError)
    return dataValue

def writeFile(value):
    # os.system(aipDrive)
    # f = open(fileAip, "a")
    # f.write(value)
    while (os.path.ismount('/media/AIP') == False):
        os.system(cutDrive)
    try:
        with open(fileAip,'w',newline='') as csvfile :
            writer = csv.DictWriter(csvfile,fieldnames=header)
            writer.writeheader()
            writer.writerow({yd:(value*1.0936133),mt:value})
    except IOError:
        print('ERROR' +IOError)
    # f.close()


## ------ MAIN ---------
while True:
    # inputSW = 0
    inputSW = GPIO.input(pinSW)
    if(inputSW == 1):
        time.sleep(1)
        valueCSV = openFile()
        writeFile(valueCSV)