예제 #1
0
def Main():
    try:
        #====================================================
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(2, GPIO.OUT)
        GPIO.setup(3, GPIO.OUT)
        GPIO.setup(4, GPIO.OUT)
        GPIO.setup(5, GPIO.OUT)
        GPIO.setup(21, GPIO.IN)
        while (True):
            a = GPIO.input(21)
            if a == GPIO.HIGH:
                GPIO.output(2, GPIO.HIGH)
                time.sleep(0.5)
                GPIO.output(2, GPIO.LOW)
                GPIO.output(3, GPIO.HIGH)
                time.sleep(0.5)
                GPIO.output(3, GPIO.LOW)
                GPIO.output(4, GPIO.HIGH)
                time.sleep(0.5)
                GPIO.output(4, GPIO.LOW)
                GPIO.output(5, GPIO.HIGH)
                time.sleep(0.5)
                GPIO.output(5, GPIO.LOW)


#=====================================================
    except Exception as ex:
        traceback.print_exc()
예제 #2
0
파일: b.py 프로젝트: JonathanEarle/SLight
 def setGPIO(system):
     GPIO.setmode(GPIO.BCM) # Set GPIO mode for pi
     
     # Sets the GPIO Pins of the PI's sensors to send input to PI 
     for i in range(0,len(sensors)):
         GPIO.setup(self._sensors.getSensor(i).pin,GPIO.IN)
         
     # Sets the GPIO Pins of the PI's LEDs to receive output from the PI 
     for i in range(0,len(LEDS)):
         GPIO.setup(self._leds.getLed(i).pin,GPIO.OUT)
예제 #3
0
def main():
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(17, GPIO.OUT)
    GPIO.setup(18, GPIO.OUT)
    GPIO.setup(22, GPIO.OUT)
    GPIO.setup(23, GPIO.OUT)
    print('Red LED on')
    GPIO.output(17, True)
    time.sleep(3)
    GPIO.output(17, False)
    time.sleep(1)
    print('Yellow LED on')
    GPIO.output(18, True)
    time.sleep(3)
    GPIO.output(18, False)
    time.sleep(1)
    print('Green LED on')
    GPIO.output(22, True)
    time.sleep(3)
    GPIO.output(22, False)
    time.sleep(1)
    print('Blue LED on')
    GPIO.output(23, True)
    time.sleep(3)
    GPIO.output(23, False)
예제 #4
0
def Main():
    try:
        GPIO.setmode(GPIO.BCM)

        GPIO.setwarnings(False)

        GPIO.setup("P8_7", GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup("P8_8", GPIO.IN, initial=GPIO.LOW)

        # GPIO.setup(4, GPIO.OUT)
        # GPIO.setup(17, GPIO.OUT, initial = GPIO.LOW)
        # GPIO.setup(18, GPIO.OUT, initial = GPIO.LOW)
        # GPIO.setup(21, GPIO.OUT, initial = GPIO.LOW)
        # GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
        # GPIO.setup(15, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
        # GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
        # GPIO.setup(26, GPIO.IN)

        while (True):
            pass
            # if (GPIO.input(23) == False):
            #     GPIO.output(4,GPIO.HIGH)
            #     GPIO.output(17,GPIO.HIGH)
            #     time.sleep(1)

            # if (GPIO.input(15) == True):
            #     GPIO.output(18,GPIO.HIGH)
            #     GPIO.output(21,GPIO.HIGH)
            #     time.sleep(1)

            # if (GPIO.input(24) == True):
            #     GPIO.output(18,GPIO.LOW)
            #     GPIO.output(21,GPIO.LOW)
            #     time.sleep(1)

            # if (GPIO.input(26) == True):
            #     GPIO.output(4,GPIO.LOW)
            #     GPIO.output(17,GPIO.LOW)
            #     time.sleep(1)

    except Exception as ex:
        traceback.print_exc()
    finally:
        GPIO.cleanup()  #this ensures a clean exit
예제 #5
0
    def init_gpio(relay_list, quiet=True):
        Logger.write.info("Initializing relays, please wait")

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(SENSOR_GPIO_PIN, GPIO.IN, pull_up_down=SENSOR_PUD)

        for pin in relay_list:
            GPIO.setup(pin, GPIO.OUT)
            GPIO.output(pin, RELAY_OFF)

        if not quiet:
            for pin in relay_list:  # cycle individual
                GPIO.output(pin, RELAY_ON)
                time.sleep(0.25)
                GPIO.output(pin, RELAY_OFF)
                time.sleep(0)

            for pin in relay_list:  # all on
                GPIO.output(pin, RELAY_ON)
            time.sleep(1.0)

            for pin in relay_list:  # all off
                GPIO.output(pin, RELAY_OFF)
예제 #6
0
import json
from web3 import Web3, HTTPProvider
from web3.contract import ConciseContract
from EmulatorGUI import GPIO
from flask import Flask, render_template, request
#from RPiSim import GPIO
# GPIO setup
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pinList = [
    14, 15, 18, 23, 24, 25, 8, 7, 12, 16, 20, 21, 2, 3, 4, 17, 27, 22, 10, 9,
    11, 5, 6, 13, 19, 26
]
for i in pinList:
    GPIO.setup(i, GPIO.OUT)

# compile your smart contract with truffle first
truffleFile = json.load(open('./build/contracts/homeAutomation.json'))
abi = truffleFile['abi']
bytecode = truffleFile['bytecode']

# web3.py instance
w3 = Web3(HTTPProvider("http://localhost:8545/"))

# Instantiate and deploy contract
contract = w3.eth.contract(abi=abi, bytecode=bytecode)

# Get transaction hash from deployed contract
tx_hash = contract.deploy(transaction={
    'from': w3.eth.accounts[0],
    'gas': 410000
예제 #7
0
from EmulatorGUI import GPIO
import threading
import time

DATA_PIN = 1
LATCH_PIN = 2
PUSH_OUT_PIN = 3
LED_COLORS = ["red", "green", "blue"]
LED_NUM_SEGS = 3

GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO.setup(DATA_PIN, GPIO.OUT)
GPIO.setup(LATCH_PIN, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(PUSH_OUT_PIN, GPIO.OUT, initial=GPIO.LOW)


class Lights():
    SLEEP_DELAY = 0.000001  # How long to wait between loops in the manual software PWM below
    TRIGGER_DELAY = 0.00000001  # How long to wait for digital signal propagation within the hardware
    PWM_TIMESLOTS = 100

    def __init__(self):
        # State of the three segments, first to third in order
        self.state = []
        for seg in range(LED_NUM_SEGS):
            self.state.append({})
            for color in LED_COLORS:
                self.state[seg][color] = 0.0
예제 #8
0
from EmulatorGUI import GPIO
#import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.OUT)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
numCount = 0


def numBottonDown(channel):
    # if
    global numCount
    numCount += 1


def numPrint(channel):
    global numCount
    if numCount != 0:
        print(numCount)
        numCount = 0


GPIO.add_event_detect(23, GPIO.FALLING, callback=numBottonDown, bouncetime=80)
GPIO.add_event_detect(24, GPIO.FALLING, callback=numPrint, bouncetime=20)
예제 #9
0
#won't have to write timeit.Timer every time
from threading import Timer

#clean all pinout settings
GPIO.cleanup()
 
#Mode of pinout numbering, BOARD or BCM available
GPIO.setmode(GPIO.BCM)
 
#List of output channels for airpumps set as output 0V
output_list = (5, 6, 12, 13, 19, 16, 26, 20, 21)

#NOTICE!!! Initial set to HIGH instead of LOW. Apparently the logic is somewhat inverted, and using initial LOW will enable
#out signal instead of disable it, making the relays close it's circuits instead of leaving them open.

GPIO.setup(5, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(6, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(12, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(13, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(19, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(16, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(26, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(20, GPIO.OUT, initial = GPIO.HIGH)
GPIO.setup(21, GPIO.OUT, initial = GPIO.HIGH)

#General times for booze and soda

sodatime = 8.0
boozetime = 2.0

예제 #10
0
def setupGPIO():
	try:
		#GPIO.setmode(GPIO.BOARD) 		# sets input to unified board pin numbers
		GPIO.setmode(GPIO.BCM)			# sets input to chip numbers, can differ per poard type

		GPIO.setwarnings(False)

		GPIO.setup(4, GPIO.OUT)
		GPIO.setup(17, GPIO.OUT, initial = GPIO.LOW)
		GPIO.setup(18, GPIO.OUT, initial = GPIO.LOW)
		GPIO.setup(21, GPIO.OUT, initial = GPIO.LOW)
		GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)
		GPIO.setup(15, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
		GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
		GPIO.setup(26, GPIO.IN)

		while(True):
			if (GPIO.input(23) == False):
				GPIO.output(4,GPIO.HIGH)
				GPIO.output(17,GPIO.HIGH)
				time.sleep(1)

			if (GPIO.input(15) == True):
				GPIO.output(18,GPIO.HIGH)
				GPIO.output(21,GPIO.HIGH)
				time.sleep(1)

			if (GPIO.input(24) == True):
				GPIO.output(18,GPIO.LOW)
				GPIO.output(21,GPIO.LOW)
				time.sleep(1)

			if (GPIO.input(26) == True):
				GPIO.output(4,GPIO.LOW)
				GPIO.output(17,GPIO.LOW)
				time.sleep(1)

	except Exception as ex:
		traceback.print_exc()
	finally:
		GPIO.cleanup() #this ensures a clean exit
예제 #11
0
def Main():

    try:
        GPIO.setmode(GPIO.BCM)

        GPIO.setwarnings(False)

        GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # Kasa Açıldı
        GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # Ev Kapısı Açıldı
        GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # Araba Açık

        GPIO.setup(25, GPIO.IN,
                   pull_up_down=GPIO.PUD_DOWN)  # Araba Kapısı Kapandı
        GPIO.setup(16, GPIO.IN,
                   pull_up_down=GPIO.PUD_DOWN)  # Ev Kapısı Kapandı
        GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)  # Kasa Kapandı

        GPIO.setup(4, GPIO.OUT,
                   initial=GPIO.HIGH)  # Kasa Açık 1, Kasa Kapalı 0
        GPIO.setup(9, GPIO.OUT, initial=GPIO.LOW)  # Ev Açık 1, Ev Kapalı 0
        GPIO.setup(17, GPIO.OUT,
                   initial=GPIO.HIGH)  # Araba Açık 1, Araba Kapalı 0

        GPIO.setup(19, GPIO.OUT, initial=GPIO.LOW)  # Nem kontrol

        GPIO.output(4, GPIO.LOW)
        GPIO.output(9, GPIO.LOW)
        GPIO.output(17, GPIO.LOW)
        Kasakapaliguncelle()
        Evkapaliguncelle()
        Arabakapaliguncelle()

        while (True):

            if (GPIO.input(14) == True):
                GPIO.output(4, GPIO.HIGH)
                Kasaacikguncelle()

            if (GPIO.input(8) == True):
                GPIO.output(4, GPIO.LOW)
                Kasakapaliguncelle()

            if (GPIO.input(15) == True):
                GPIO.output(9, GPIO.HIGH)
                Evacikguncelle()

            if (GPIO.input(16) == True):
                GPIO.output(9, GPIO.LOW)
                Evkapaliguncelle()

            if (GPIO.input(18) == True):
                GPIO.output(17, GPIO.HIGH)
                Arabaacikguncelle()

            if (GPIO.input(25) == True):
                GPIO.output(17, GPIO.LOW)
                Arabakapaliguncelle()

        con.close()
    except Exception as ex:
        traceback.print_exc()
    finally:
        GPIO.cleanup()
예제 #12
0
    elif req.door_id == 3:
        GPIO.output(4, GPIO.HIGH)
        time.sleep(1)
        GPIO.output(4, GPIO.LOW)

    return True


def door_server():
    rospy.init_node('door_server')
    s = rospy.Service('door', opendoor, handle_door)
    rospy.loginfo("ready to open doors ")
    rospy.spin()


if __name__ == "__main__":
    try:
        GPIO.setmode(GPIO.BCM)

        GPIO.setwarnings(False)

        GPIO.setup(2, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(3, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(4, GPIO.OUT, initial=GPIO.LOW)

        door_server()
    except Exception as ex:
        traceback.print_exc()
    finally:
        GPIO.cleanup()  #this ensures a clean exit
예제 #13
0
파일: a.py 프로젝트: JonathanEarle/SLight
def setGPIOIn(sensors):
    for i in range(0, len(sensors)):
        GPIO.setup(sensors[i], GPIO.IN)
예제 #14
0
##import RPi.GPIO as GPIO
from EmulatorGUI import GPIO
import time
##Coloco mis pin de salida
GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

#genero el ciclo para el semaforo 14 15 18
while True:
   GPIO.output(14, GPIO.HIGH)
   GPIO.output(15, GPIO.LOW)
   GPIO.output(18, GPIO.LOW)
   time.sleep(5)
   GPIO.output(14, GPIO.LOW)
   GPIO.output(15, GPIO.HIGH)
   GPIO.output(18, GPIO.LOW)
   time.sleep(1)
   GPIO.output(14, GPIO.LOW)
   GPIO.output(15, GPIO.LOW)
   GPIO.output(18, GPIO.HIGH)
   time.sleep(5)
    
    
예제 #15
0
from EmulatorGUI import GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN)
GPIO.setup(7, GPIO.OUT)

while True:
    if GPIO.input(3):
        GPIO.output(7, GPIO.LOW)
    else:
        GPIO.output(7, GPIO.HIGH)
예제 #16
0
from EmulatorGUI import GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
while True:
    GPIO.output(11, False)
    GPIO.output(13, False)
    GPIO.output(15, True)
    time.sleep(5)
    GPIO.output(11, False)
    GPIO.output(13, True)
    GPIO.output(15, False)
    time.sleep(5)
    GPIO.output(11, True)
    GPIO.output(13, False)
    time.sleep(5)
예제 #17
0
##import RPi.GPIO as GPIO
#importo libreria
from EmulatorGUI import GPIO
import requests
import time
import json

GPIO.setmode(GPIO.BCM)
#configuro pin 23 com entrada y activo
#esta activacion en la resistencia pin 23 con PUD_UP
#esto intrumpe tensión con voltaje 3.3v
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
#  configuramos el pin 23 como salida para el led
GPIO.setup(24, GPIO.OUT)
# definimos dos variables para guardar el estado del led
# por defecto el estado del led es False (apagado)
switch_state = False
# por defecto el estado anterior es True (encendido)
old_input_state = True  # activada
# bucle infinito que recoge el estado del pin18
# cada vez que presionamos el botón,el estado del switch
# alterna entre True/False
while True:
    # guardo en una variable el estado del pin
    new_input_state = GPIO.input(23)
    # si el estado es False (presionado),y el estado
    # anterior es True cambiamos el valor del switch
    if new_input_state == False and old_input_state == True:
        switch_state = not switch_state
        ##print('Boton presionado')
        ##print(switch_state)
예제 #18
0
from flask import request
from flask_api import FlaskAPI
from EmulatorGUI import GPIO

GPIO.setmode(GPIO.BCM)
LEDS = {"green":16,"red":18}
GPIO.setup(LEDS["green"],GPIO.OUT)
GPIO.setup(LEDS["red"],GPIO.OUT)
#Se inicializa el framework FlaskAPI el cual permite generar interfaz web para consumir los metodos
app = FlaskAPI(__name__)


#Ruta principal del api
@app.route('/',methods = ["GET"])
def api_root():
    return {"led_url":request.url+"led/(green|red)","led_url_POST":{"state":"(0|1)"},"Levis":"Tabares"}

@app.route('/led/<color>/', methods=["GET", "POST"])
def api_leds_control(color):
    if request.method == "POST":
        if color in LEDS:
            #GPIO.output(18,True)
            GPIO.output(LEDS[color], int(request.data.get("state")))      
   
    return {color: GPIO.getStatePinOut(LEDS[color])}
if __name__== "__main__":
    app.run()
##import RPi.GPIO as GPIO
from EmulatorGUI import GPIO
import time

#asigno el nodo al puerto GPIO
GPIO.setmode(GPIO.BCM)
# Configuro si el pin es entrada o salida
GPIO.setup(7, GPIO.OUT)

while True:
    # envio la señal por ese puerto
    GPIO.output(7, True)
    time.sleep(1)
    GPIO.output(7, False)
    time.sleep(1)
예제 #20
0
 def setGPIOOut(self):
     for i in range(0, self.numLeds()):
         GPIO.setup(self._leds[i].pin, GPIO.OUT)
예제 #21
0
##import RPi.GPIO as GPIO
from EmulatorGUI import GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.OUT)
GPIO.setup(15, GPIO.IN)

while True:
    if GPIO.input(14):
        GPIO.output(15, False)
    else:
        GPIO.output(15, True)
    client = Client(url)

    userName = '******'
    password = '******'
    recipientNumber = '01521418737'
    smsText = 'If this SMS reaches to you then congratulations! Our SMS system is working!!---hafiz031'
    smsType = 'TEXT'

    maskName = ''
    campaignName = ''

    client.service.OneToOne(userName,password,recipientNumber,smsText,smsType,maskName,campaignName)

 
if __name__ == '__main__':
    GPIO.setup(GPIO_BEGIN_PIN, GPIO.IN)
    GPIO.setup(GPIO_END_PIN, GPIO.IN)
    while 1:
        start_time, end_time = 0, 0
        
        while GPIO.input(GPIO_BEGIN_PIN) == GPIO.LOW:
            time.sleep(0.001)
            start_time = time.time()
        end_time = 0
     
        while GPIO.input(GPIO_END_PIN) == GPIO.LOW and time.time()-start_time < TIMEOUT:
            time.sleep(0.001)
        else:
            end_time = time.time()
        if(start_time!=end_time):
            speed = DISTANCE / (end_time - start_time)
예제 #23
0
import sys, termios, tty, os, time
from EmulatorGUI import GPIO
a = 23
b = 24
c = 22
d = 27
x = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(a, GPIO.OUT)
GPIO.setup(b, GPIO.OUT)
GPIO.setup(c, GPIO.OUT)
GPIO.setup(d, GPIO.OUT)


def mfl():
    GPIO.output(a, True)
    GPIO.output(c, True)


def mfr():
    GPIO.output(b, True)
    GPIO.output(d, False)


def mbl():
    GPIO.output(c, True)
    GPIO.output(a, False)


def mbr():
    GPIO.output(d, True)
예제 #24
0
from EmulatorGUI import GPIO
#import RPi.GPIO as GPIO
import time
import os
from datetime import datetime
import random, glob, subprocess

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)

previous = None
previoush = None


def rndhmp3(previous):
    pattern = "/home/pi/or/mp3h/*.mp3"  # (or "*.*")
    randomfile = random.choice(glob.glob(pattern))
    if randomfile == previoush:
        return rndhmp3(previoush)
    else:
        return randomfile


def rndmp3(previous):
    pattern = "/home/pi/or/mp3/*.mp3"  # (or "*.*")
    randomfile = random.choice(glob.glob(pattern))
    if randomfile == previous:
        return rndhmp3(previous)
    else:
예제 #25
0
파일: a.py 프로젝트: JonathanEarle/SLight
def setGPIOOut(LEDS):
    for i in range(0, len(LEDS)):
        GPIO.setup(LEDS[i], GPIO.OUT)
예제 #26
0
 def setGPIOIn(self):
     for i in range(0, self.numSensors()):
         GPIO.setup(self._sensors[i].pin, GPIO.IN)