コード例 #1
0
ファイル: display_stat.py プロジェクト: paulloft/raspberry
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
try:
    range = xrange
except NameError:
    pass
try:
    input = raw_input
except NameError:
    pass

range_pins = [3, 24]  #range of GPIO pins to check
inv_pins = [4, 6, 9, 14, 17, 20]  #pins that aren't onboard GPIOs
v_modes = [GPIO.PUD_DOWN, GPIO.PUD_UP, GPIO.PUD_OFF]  #Pull's states
v_modes_str = ["Down", "Up", "Off"]

GPIO.setmode(GPIO.BOARD)


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)


while True:
    try:
        modenum = int(
            input(
                'Choose resistor pull modes: \n( 0 - Active Pull Down, 1 - Active Pull Up, 2 - Disable Pull, 3 - Quit )\n'
コード例 #3
0
from __future__ import print_function
import NPi.GPIO as GPIO

validPins = [11,12,13,15]

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11,GPIO.IN)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.IN)
GPIO.setup(15,GPIO.OUT)

for pin in validPins:
    fun = GPIO.gpio_function(pin)
    print(fun)
コード例 #4
0
ファイル: display_stat.py プロジェクト: paulloft/raspberry
def setupGPIO():
    GPIO.setwarnings(False)  # Ignore warning for now
    GPIO.setmode(GPIO.BOARD)  # Use physical pin numbering
    GPIO.setup(PIN_BTN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    return ()
コード例 #5
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()
コード例 #6
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)))
コード例 #7
0
ファイル: piscaLed.py プロジェクト: marcosViniciusps/nanopi
#!/usr/bin/env python
import NPi.GPIO as GPIO
import time
PIN_NUM = 7

GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.OUT)
while True:
    print('Led aceso')
    GPIO.output(PIN_NUM,True)
    time.sleep(3)
    GPIO.output(PIN_NUM,False)
    print('led apagado')
    time.sleep(3)
コード例 #8
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()
コード例 #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
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)
コード例 #11
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()
コード例 #12
0
from __future__ import print_function
import NPi.GPIO as GPIO

validPins = [3, 5, 8, 7, 10, 12, 11, 13, 16, 15, 18, 19, 22, 21, 24, 23, 26]

GPIO.setmode(GPIO.BOARD)

for pin in validPins:
    fun = GPIO.gpio_function(pin)
    print(fun)
コード例 #13
0
#/usr/bin/env python
import NPi.GPIO as GPIO
import time

try:
    input = raw_input
except NameError:
    pass

PIN_NUM = 11

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

p = GPIO.PWM(PIN_NUM, 0.5)
p.start(50)

input("Press Enter to stop:")

p.stop()
GPIO.cleanup()
コード例 #14
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)
コード例 #15
0
ファイル: pwm_test2.py プロジェクト: vad-babushkin/NPi.GPIO
import NPi.GPIO as GPIO
import time

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

frequency = 50
p = GPIO.PWM(PIN_NUM, frequency)
p.start(0)

try:
    while True:
        for dutyCycle in range(0, 100, 5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
        for dutyCycle in range(100, 0, -5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
except KeyboardInterrupt:
    pass

p.stop()
GPIO.cleanup()
コード例 #16
0
        "Error importing GPIO modules! This is probably because you need superuser privileges. You can achieve this by using 'sudo' to run your script"
    )
    sys.exit(-1)
import time

try:
    input = raw_input
except NameError:
    pass

print("Inizializing...\n")
range_pins = [3, 24]  #range of board GPIO pins to check
inv_pins = [4, 6, 9, 14, 17, 20]  #pins that aren't onboard GPIOs
v_modes_str = ["LOW", "HIGH"]

GPIO.setmode(GPIO.BOARD)

time.sleep(0.2)

#print "Board revision:"
#print GPIO.RPI_INFO
#print GPIO.RPI_REVISION
print("\nNPi.GPIO version:")
print(GPIO.VERSION)

time.sleep(1)

while True:
    try:
        pin = int(
            input(
コード例 #17
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()
コード例 #18
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")
コード例 #19
0
pinSW = 8

# PATH File
fileAip = '/media/AIP/Cut-01.csv'
fileCut = '/media/CuttingMachine/'

# Config Mount I/O to Windows
cutDrive = 'sudo mount.cifs //PathCutting/data /media/AIP -o rw,uid=pi,password=eseuser'
aipDrive = 'sudo mount.cifs //PathAIP/data /nedia/AIP -o rw,uid=pi,password=eseuser'

# Config CSV
mt = 'MT'
yd = 'YD'
header =  [yd,mt]

GPIO.setmode(GPIO.BOARD)
GPIO.setup(pinSW,GPIO.IN)

reader = csv.reader(open("csvfile.csv"), delimiter=";")
included_cols = [22]
count = 0
content = []

def openFile():
    # os.system(cutDrive)
    now = datetime.now()  # current date and time
    nowdate = now.strftime("%Y%m%d")
    fileReport = 'Reporting_' + nowdate + '-Job.csv'
    while (os.path.ismount('/media/AIP') == False):
        os.system(cutDrive)
    try: