Example #1
0
def forward(tf):

    init()
    gpio.output (7, True)
    gpio.output (11, True)
    time.sleep(tf) '
    gpio.cleanup()
Example #2
0
def reverse(tf):

    init()
    gpio.output (7, False)
    gpio.output (11, False)
    time.sleep(tf)
    gpio.cleanup()
Example #3
0
def turn_right(tf):

    init()
    gpio.output (7, False)
    gpio.output (11, True)
    time.sleep(tf)
    gpio.cleanup()
Example #4
0
def pivot_right(tf):
    init()
    gpio.output (7, False)
    gpio.output (11, True)
    gpio.output (13, False)
    gpio.output (15, True)
    time.sleep(tf)
    gpio.cleanup()
Example #5
0
def pivot_left(tf):
    init()
    gpio.output (7, True)
    gpio.output (11, False)
    gpio.output (13, True)
    gpio.output (15, False)
    time.sleep(tf)
    gpio.cleanup()
Example #6
0
def turn_left(tf):
    init() 0
    gpio.output (7, True)
    gpio.output (11, True)
    gpio.output (13, True)
    gpio.output (15, False)
    time.sleep(tf)
    gpio.cleanup()
Example #7
0
def forward(tf):
    init()
    gpio.output (7, True)
    gpio.output (11, False)
    gpio.output (13, False)
    gpio.output (15, True)
    time.sleep(tf) 
    gpio.cleanup()
Example #8
0
def setRudder(pin, angle):

    dutyChange = int(angle / 18) + 1

    try:
        print("Attempting to reset rudder servo")
        pin.start(1)
        pin.ChangeDutyCycle(dutyChange)
        time.sleep(5)  #until change has been made.
    except:
        print("error,, servo contact has been interrupted")
        return "Failed"
    finally:
        pin.stop()
        GPIO.cleanup()

    return "Success"
Example #9
0
def setSail(pin, angle):

    dutyChange = int(angle / 18) + 1

    try:
        print("Attempting to reset sail servo")
        pin.start(0)  # Sets the initial position.
        pin.ChangeDutyCycle(
            dutyChange
        )  # 7 is the middle point for the servo, 1 is the start, 12 to 14 is the end.
        time.sleep(5)  # Sleep until change is made.
    except:
        print("Error, servo contact has been interrupted")
        return "Failed"
    finally:
        pin.stop()  # Stops the pin running high.
        GPIO.cleanup()  # Resets pins to default starting state.

    return "Success"
Example #10
0
 def lit(self,prob):
  i=0
  GPIO.setmode(GPIO.BOARD)
  GPIO.setup(7,GPIO.OUT)
  GPIO.setwarnings(False)
  while(i>0):
   if prob>0.5:
    GPIO.output(7,GPIO.HIGH)
    time.sleep(1)
    GPIO.output(7,GPIO.LOW)
    GPIO.output(7,GPIO.LOW)
    time.sleep(1)
    i-=1
   else:
    GPIO.output(7,GPIO.LOW)
    time.sleep(1)
    i-=1
  GPIO.output(7,GPIO.LOW) 
  GPIO.cleanup()
def park():
    GPIO.cleanup()
Example #12
0
def press_button():
    log('Debug: press_button')
    import Rpi.GPIO as GPIO

    GPIO.setmode(GPIO.BOARD)

    GPIO.setup(SERVER_POWER, GPIO.OUT)
    GPIO.setup(SERVER_RESET, GPIO.OUT)
    GPIO.setup(DESKTOP_POWER, GPIO.OUT)
    GPIO.setup(DESKTOP_RESET, GPIO.OUT)
    log('Debug: set up GPIO')

    try:
        if machine_to_control == "S":
            if button_to_press == "P":  # Server Power
                GPIO.output(SERVER_POWER, True)
                log('Info: pressing server power button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(SERVER_POWER, False)
                log('Info: button released')
            elif button_to_press == "R":  # Server Reset
                GPIO.output(SERVER_RESET, True)
                log('Info: pressing server reset button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(SERVER_RESET, False)
                log('Info: button released')
            elif button_to_press == "PH":  # Server Power Hold
                GPIO.output(SERVER_POWER, True)
                log('Info: holding server power button')
                time.sleep(BUTTON_HOLD_TIME)
                GPIO.output(SERVER_POWER, False)
                log('Info: button released')
        else:
            log('Error: machine variables not set correctly')
            GPIO.cleanup()
            return

        if machine_to_control == "D":
            if button_to_press == "P":  # Desktop Power
                GPIO.output(DESKTOP_POWER, True)
                log('Info: pressing desktop power button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(DESKTOP_POWER, False)
                log('Info: button released')
            elif button_to_press == "R":  # Desktop Reset
                GPIO.output(DESKTOP_RESET, True)
                log('Info: pressing desktop reset button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(DESKTOP_RESET, False)
                log('Info: button released')
            elif button_to_press == "PH":  # Desktop Power Hold
                GPIO.output(DESKTOP_POWER, True)
                log('Info: holding desktop power button')
                time.sleep(BUTTON_HOLD_TIME)
                GPIO.output(DESKTOP_POWER, False)
                log('Info: button released')
        else:
            log('Error: desktop variables not set correctly')
            GPIO.cleanup()
            return
    # TODO: catch and log the error.
    finally:
        GPIO.cleanup()
Example #13
0
def destroy():
    GPIO.output(LedPin, GPIO.LOW)
    GPIO.cleanup()
      #It may take a second or two to get good data
      #print gpsd.fix.latitude,', ',gpsd.fix.longitude,'  Time: ',gpsd.utc
 
        os.system('clear')
	    latitude = gpsd.fix.latitude
	    longitude = gpsd.fix.longitude
	    time = gpsd.utc,' + ', gpsd.fix.time
	  
	  #GPIO read
	    GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
	    button = GPIO.input(11)
	  
	  #if button is pressed than write to file
	    if button == False:
	        gpsdLog = open("GPSLOG.txt", "a")
	        print(latitude, sep = "*", end="\n",file=gpsdLog)
		    print(longitude, sep = "*", end="\n",file=gpsdLog)
		    print(time, sep = "*", end="\n",file=gpsdLog)
		    button = True
		    time.sleep(3) #delay
	    else:
            time.sleep(3) 
		    print("variables are resetting")
 
  except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
    print ("\nKilling Thread...")
    gpsp.running = False
    gpsp.join() # wait for the thread to finish what it's doing
	GPIO.cleanup() 
  print ("Done.\nExiting.")
  GPIO.cleanup() 
Example #15
0
def destroy():
    GPIO.output(fart, GPIO.LOW)  #led off
    GPIO.cleanup()  #Release resource
Example #16
0
def gameover():
	gpio.output(31, FALSE)
	gpio.output(33, FALSE)
	gpio.output(35, FALSE)
	gpio.output(37, FALSE)
	gpio.cleanup()
Example #17
0
import Rpi.GPIO as gpio
import time

gpio.setmode(gpio,BCM)
gpio.setup(21,gpio.OUT)

while(1):
	x=input('Enter the state')
	if x == 'ON':
		gpio.output(21,1)
		print('LED ON')
	if x =='OFF'
		gpio.output(21,0)
		print('LED OFF')
gpio.cleanup()
Example #18
0
import Rpi.GPIO as gpio
# RPI gpio library
import time
#module for time
import random
# module for randomised number

gpio.setmode(gpio,BCM)	#used to set the RPI mode
gpio.setup(21,gpio.OUT) #used to set pin as output

while(1):
    otp = random.randint(10000,99999)
    print('OTP is' + otp)

    a = int(input("Enter the OTP"))
    if a == otp:
        print("OTP Accepted")
        gpio.output(21,1)	
	    print('LED ON')
	    time.sleep(2)
        gpio.output(21,0)	
    else:
        print("Invalid OTP")
        gpio.output(21,0)
	
gpio.cleanup()			# clear existing states of GPIO
Example #19
0
# this python file use for insert sensor data in database

#import MyDB connection module
import MyDB
db = MyDB.DB()
import Rpi.GPIO as GPIO
import time

sensorPin1 = 18 #Broadcom pin 18
#pin setup:
GPIO.setmode(GPIO.BCM) #Broadcom pin numbering scheem
GPIO.setup(sensorPin1, GPIO.IN, pull_up_down=GPIO.PUD_UP) # sensor pin set as input
user_id = 1023
data = [user_id]

try:
    while 1:
        if GPIO.input(sensorPin1):
            db.execute("INSERT INTO Zones (user_id,zone1) \
                  VALUES (%s, NOW() )", [data]);

            db.commit()
            print "Records created successfully";
            db.close()

except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:

    GPIO.cleanup() # cleanup all GPIO
Example #20
0
 def destroy(self):
     GPIO.cleanup()
Example #21
0
# !/usr/bin/python3
# -- coding: UTF-8 --
# Author   :WindAsMe
# Date     :18-7-24 下午12:49
# File     :detectButton.py
# Location:/Home/PycharmProjects/..
import Rpi.GPIO as GPIO
import time

# Pin Definition
butPin = 12

# Pin Setup
GPIO.setmode(GPIO.BOARD)
GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

print("Running...")

try:
    while True:
        if GPIO.input(butPin):
            print("Released!")
        else:
            print("Pressed!")
        time.sleep(0.25)
except KeyboardInterrupt:
    GPIO.cleanup()
    print("Terminal!")
Example #22
0
def press_button():
    log('Debug: press_button')
    import Rpi.GPIO as GPIO

    GPIO.setmode(GPIO.BOARD)

    GPIO.setup(SERVER_POWER, GPIO.OUT)
    GPIO.setup(SERVER_RESET, GPIO.OUT)
    GPIO.setup(DESKTOP_POWER, GPIO.OUT)
    GPIO.setup(DESKTOP_RESET, GPIO.OUT)
    log('Debug: set up GPIO')

    try:
        if machine_to_control == "S":
            if button_to_press == "P":  # Server Power
                GPIO.output(SERVER_POWER, True)
                log('Info: pressing server power button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(SERVER_POWER, False)
                log('Info: button released')
            elif button_to_press == "R":  # Server Reset
                GPIO.output(SERVER_RESET, True)
                log('Info: pressing server reset button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(SERVER_RESET, False)
                log('Info: button released')
            elif button_to_press == "PH":  # Server Power Hold
                GPIO.output(SERVER_POWER, True)
                log('Info: holding server power button')
                time.sleep(BUTTON_HOLD_TIME)
                GPIO.output(SERVER_POWER, False)
                log('Info: button released')
        else:
            log('Error: machine variables not set correctly')
            GPIO.cleanup()
            return

        if machine_to_control == "D":
            if button_to_press == "P":  # Desktop Power
                GPIO.output(DESKTOP_POWER, True)
                log('Info: pressing desktop power button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(DESKTOP_POWER, False)
                log('Info: button released')
            elif button_to_press == "R":  # Desktop Reset
                GPIO.output(DESKTOP_RESET, True)
                log('Info: pressing desktop reset button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(DESKTOP_RESET, False)
                log('Info: button released')
            elif button_to_press == "PH":  # Desktop Power Hold
                GPIO.output(DESKTOP_POWER, True)
                log('Info: holding desktop power button')
                time.sleep(BUTTON_HOLD_TIME)
                GPIO.output(DESKTOP_POWER, False)
                log('Info: button released')
        else:
            log('Error: desktop variables not set correctly')
            GPIO.cleanup()
            return
    # TODO: catch and log the error.
    finally:
        GPIO.cleanup()