Ejemplo n.º 1
0
def makeGrogg2():
    GPIO.output(soda_2, False)
    GPIO.output(liquor_2, False)
    sprit = Timer(1.9, turnOffBooze2)
    virke = Timer(8.5, turnOffSoda2)
    sprit.start()
    virke.start()
Ejemplo n.º 2
0
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])}
Ejemplo n.º 3
0
def makeGrogg1():
    GPIO.output(soda_1, False)
    GPIO.output(liquor_1, False)
    sprit = Timer(1.9, turnOffBooze1)
    virke = Timer(8.5, turnOffSoda1)
    sprit.start()
    virke.start()
Ejemplo n.º 4
0
def makeGrogg4():
    GPIO.output(liquor_4, False)

    sprit = Timer(1.9, turnOffBooze4)

    sprit.start()
    virke.start()
Ejemplo n.º 5
0
def control(pin, action):
    if pin == 'fourteen':
        actuator = 14
    if pin == 'fifteen':
        actuator = 15
    if pin == 'eighteen':
        actuator = 18
    if pin == 'twentythree':
        actuator = 23
    if pin == 'twentyfour':
        actuator = 24
    if pin == 'twentyfive':
        actuator = 25
    if pin == 'eight':
        actuator = 8
    if pin == 'seven':
        actuator = 7
    if pin == 'twelve':
        actuator = 12
    if pin == 'sixteen':
        actuator = 16
    if pin == 'twenty':
        actuator = 20
    if pin == 'twentyone':
        actuator = 21
    if pin == 'two':
        actuator = 2
    if pin == 'three':
        actuator = 3
    if pin == 'four':
        actuator = 4
    if pin == 'seventeen':
        actuator = 17
    if pin == 'twentyseven':
        actuator = 27
    if pin == 'twentytwo':
        actuator = 22
    if pin == 'ten':
        actuator = 10
    if pin == 'nine':
        actuator = 9
    if pin == 'eleven':
        actuator = 11
    if pin == 'five':
        actuator = 5
    if pin == 'six':
        actuator = 6
    if pin == 'thirteen':
        actuator = 13
    if pin == 'nineteen':
        actuator = 19
    if pin == 'twentysix':
        actuator = 26

    if action == 'on':
        GPIO.output(actuator, GPIO.HIGH)
    if action == 'off':
        GPIO.output(actuator, GPIO.LOW)
Ejemplo n.º 6
0
def main():
    try:
        system=System()
        system.setGPIO()
        
    except KeyboardInterrupt:
            run = False
    finally:
        GPIO.cleanup();
Ejemplo n.º 7
0
    def stop(self):
        self.mirror.stop()
        self.led_strip.stop()
        self.sound.stop(100)
        # Let the thread finish
        if self.mirror.thr is not None:
            while self.mirror.thr.isAlive():
                Logger.write.info("waiting for thread to finish")
                pass

        GPIO.output(RELAYS[1], RELAY_OFF)
Ejemplo n.º 8
0
def main(argv):
    # TODO: Make mirror display diagnostic info on startup (especially warnings)
    # TODO: Make mirror clear warnings and start loop on first sensor activation (or after X seconds?)

    log = Logger()  # this has to be called at least once
    Logger.write.info('Starting up')
    try:
        Logger.write.debug('Initializing pygame')
        pygame.init()
    except (KeyboardInterrupt, SystemExit) as err:
        Logger.write.error('FATAL:' + err)
        raise

    relay_list = list(RELAYS.values())
    MirrorIO.init_gpio(relay_list, quiet=False)

    sensor = ActivationSensor(relay_list)
    last_input_state = sensor.read_input_state

    done = False

    try:
        log.write.info('Ready, starting loop')
        while not done:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    done = True
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        new_state = not sensor.switch_override_state
                        log.write.info("Setting state " + str(new_state))
                        sensor.input_override(new_state)
                    elif event.key == pygame.K_ESCAPE or event.key == pygame.K_q:
                        done = True

            input_state = sensor.read_input_state()
            if input_state != last_input_state:
                time.sleep(DEBOUNCE_TIME)  # wait to make sure it really changed
                if input_state != last_input_state:
                    last_input_state = input_state
                    sensor.state_changed(input_state)
            time.sleep(0.1)
    except (KeyboardInterrupt, SystemExit):
        # TODO: fix GPIO emulator threading bug that prevents clean shutdown
        GPIO.cleanup()
        sys.exit
    finally:
        sensor.dme.stop()
        GPIO.cleanup()
        sys.exit
Ejemplo n.º 9
0
def scan(S):
    curr = GPIO.input(S)
    if curr != 0:  # For python 3.5
        # if curr ==0: # For python 2.7
        return S
    else:
        return 0
Ejemplo n.º 10
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
Ejemplo n.º 11
0
    def state_changed(self, state):
        Logger.write.info("pin status: " + str(state))
        if state == True:

            if not self.sound.is_busy():
                self.sound.play()
            else:
                Logger.write.info("Sound already playing")

            # time.sleep(1.5)
            # GPIO.output(RELAYS[1], RELAY_ON)  # relay 1
            # time.sleep(2)
            self.led_strip.run()
            self.mirror.run()

        else:
            self.mirror.stop()
            self.led_strip.stop()
            time.sleep(1.5)
            self.sound.stop()

            GPIO.output(RELAYS[1], RELAY_OFF)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
import os
import pickle
import time
import threading
# import serverEnd
# import serverStart
# import clientEnd
# import clientStart
import datetime
import time
import calendar

# import RPi.GPIO as GPIO
from EmulatorGUI import GPIO

GPIO.setmode(GPIO.BCM)
# Firebase =firebase.FirebaseApplication('https://prog-c99a8.firebaseio.com/')
Firebase = firebase.FirebaseApplication('https://slight-91c01.firebaseio.com/')


def pushData(dataModel):
    ts = time.time()
    hour = datetime.datetime.fromtimestamp(ts).strftime("%H")
    minute = datetime.datetime.fromtimestamp(ts).strftime("%M")
    day = datetime.datetime.fromtimestamp(ts).strftime("%d")
    year = datetime.datetime.fromtimestamp(ts).strftime("%Y")
    month = datetime.datetime.fromtimestamp(ts).strftime("%m")
    parent = "Pi_" + str(
        dataModel["id"]) + "/" + year + "/" + calendar.month_name[int(
            month)] + "/" + day + "/"
    Firebase.put(parent + "/" + hour + "/" + str(minute), "No Of Cars",
Ejemplo n.º 14
0
def handle_door(req):
    rospy.loginfo('sending open door command to door %s', req.door_id)
    if req.door_id == 1:
        GPIO.output(2, GPIO.HIGH)
        time.sleep(1)
        GPIO.output(2, GPIO.LOW)
    elif req.door_id == 2:
        GPIO.output(3, GPIO.HIGH)
        time.sleep(1)
        GPIO.output(3, GPIO.LOW)
    elif req.door_id == 3:
        GPIO.output(4, GPIO.HIGH)
        time.sleep(1)
        GPIO.output(4, GPIO.LOW)

    return True
Ejemplo n.º 15
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
Ejemplo n.º 16
0
def turnOffBooze3():
    GPIO.output(liquor_3, True)
Ejemplo n.º 17
0
def lightoff(LEDS, i):
    GPIO.output(LEDS[i], GPIO.LOW)
Ejemplo n.º 18
0
def main():
    try:
        #Variables

        # Hard Coded LEDs and sensors as it relates to the PI's GPIO Pins
        LEDS = [
            15, 18, 23, 24, 8, 7, 12, 16, 21, 26, 19, 13, 5, 11, 9, 10, 27, 17,
            4, 3
        ]
        sensors = [14, 25, 20, 6, 22]
        #LEDS = [16,12,17,27,5,20,19,21]
        #sensors = [23,18]
        vehicles = [
        ]  # An array that contains vehicles that are currently traversing the PI's track. The data each element contain is a dict in the format of: {"currentPos": CurrentPos, "timePlaced": TimePlaced, "speed": Speed, "visionRange": VisionRange}

        LEDsMult = int(
            len(LEDS) /
            len(sensors))  # How many LEDs that is between two sensors
        sensorsNum = len(sensors)  # How many sensors that were entered
        sensorTime = [
            0
        ] * sensorsNum  # Time at which the sensor was passed, initialized to 0 because that is the lowest possible time that can be achieved
        sensorState = [
            0
        ] * sensorsNum  # Since the sensor is 'enabled' for the length of time the vehicle passes near the sensor, this is used to keep check of the exact point where the state changes from 0 to 1 which dictates exactly when the car has passed sensor.
        expectedSensorPass = [
            -1
        ] * sensorsNum  # Keeps note of which vehicle is expected to pass which sensor, this is necessary for speed updates to occur to the correct vehicle as it passes another sensor

        LEDsNum = len(LEDS)  # How many LEDs that were entered
        LEDsStateNew = [
            0
        ] * LEDsNum  # used to keep check of what the new state is after the set of "stepThrough" functions are run,single element can be, 1 meaning light on, 0 meaning light off, or - meaning keep corresponding state of LEDsState. Ensures a vehicle's associated LEDs does not clash with another vehicle's LEDs
        LEDsState = [
            0
        ] * LEDsNum  # single element can be either 1 meaning light on or 0 meaning light off

        LEDsDistance = [
        ]  # Distance from one sensor to another sensor, this is for the situation where street lights were already placed but with uneven distances between them for any particular reason
        sensorsDistance = []  # similar reason ^^
        lastPiSensorTime = -1  # The time the last sensor in the track was passed, this is stored to pass to the leading PI to calculate vehicles speed
        run = True

        # data to nbe use for pushing into firebase
        id = 1
        dataModelInit = {
            'id': id,
            'avgSpeed': 0,
            'numOfNewCars': 0,
            'LEDsTurnedOn': {}
        }
        dataModel = dataModelInit
        now = datetime.datetime.now()
        min = now.minute
        secChanged = 0
        LEDsModel = genLEDsFirebaseModel(LEDsNum)
        timeBeforeLEDUpdate = time.clock()

        # Set GPIO pins
        setGPIOIn(sensors)
        setGPIOOut(LEDS)

        # Init distance
        setAllsensorsDistance(sensors, sensorsDistance, 5)
        setAllLEDsDistance(sensors, sensorsDistance, LEDsMult, LEDsDistance)

        # Initialize data to be sent and reveived between PIs to ensure no garbage data
        passToLeadingPi = PassToLeadingPi()
        receiveFromTrailingPi = ReceiveFromTrailingPi()
        passToTrailingPi = PassToTrailingPi()
        receiveFromLeadingPi = ReceiveFromLeadingPi()

        # Used for setting up which light and sensor goes to which physical location

        # Init States
        initSensorState(sensorState, sensorsNum)
        initLEDsState(LEDsState, LEDsNum)

        while run:
            initLEDsStateNew(LEDsStateNew,
                             LEDsNum)  # Ensures the stateNew is empty

            # Pi to Pi communication
            receiveFromLeadingPi = ReceiveFromLeadingPiStore(
                receiveFromLeadingPi, LEDsStateNew)
            receiveFromTrailingPi = ReceiveFromTrailingPiStore(
                receiveFromTrailingPi, LEDsStateNew, expectedSensorPass,
                vehicles, lastPiSensorTime, sensorsNum, passToLeadingPi)

            # Keeps scanning for motion
            for i in range(0, sensorsNum):
                state = scan(sensors[i])
                if state and sensorState[
                        i] == 0:  # Vehicle has now passed the sensor
                    sensorTime[i] = time.clock(
                    )  #the time which the sensor was triggered is stored

                    # passToLeadingPi-LastSensorTime
                    if state == sensorsNum - 1:
                        passToLeadingPi.lastSensorTime(sensorTime[i])

                    sensorState[i] = 1

                    #*(to delete fnction isNewVehicle) Create new vehicle if 1st sensor is passed
                    if i == 0:
                        # AddVehicle
                        vehicles.append(vehicle(0, sensorTime[i], -1, -1))
                        addVehicleStartingLEDs(passToLeadingPi,
                                               passToTrailingPi, LEDsMult,
                                               LEDsNum, LEDsState, i)
                        updateExpectedSensorPass(
                            expectedSensorPass, sensorsNum, passToLeadingPi,
                            i + 1,
                            len(vehicles) - 1
                        )  # Update expectedSensorPass of the next index to this vehicle that was just appended. This is to ensure that the correct vehicle speed is updated

                        #increment car counter to pass to firebase
                        dataModel[
                            "numOfNewCars"] = dataModel["numOfNewCars"] + 1
                    else:
                        # Since vehicle already exist, update its speed with the new speed
                        if vehicles[len(
                                vehicles
                        ) - 1]["speed"] == -1:  # If the last vehicle that entered the track speed=-1, then the starting lights must be removed
                            removeVehicleStartingLEDs(LEDsStateNew,
                                                      passToLeadingPi,
                                                      passToTrailingPi,
                                                      LEDsMult, LEDsNum, i - 1)
                            #print(passToTrailingPi.getData()["fade"])

                        if i - 1 < 0:  # if this condition is met, then the sensorTime of the previous pi will be required to complete the speed update
                            vehicles[
                                expectedSensorPass[i]]["speed"] = calcSpeed(
                                    sensorsDistance[i],
                                    sensorTime[i] - lastPiSensorTime)
                        else:
                            #*(for now treat it as though there is no previous pi, this line will be removed)
                            vehicles[
                                expectedSensorPass[i]]["speed"] = calcSpeed(
                                    sensorsDistance[i],
                                    sensorTime[i] - sensorTime[i - 1])

                        #Update vision range because speed changed
                        vehicles[expectedSensorPass[i]][
                            "visionRange"] = calcVisionRange(
                                vehicles[expectedSensorPass[i]]["speed"])

                        #add onto maxSpeed with current speed value to calulate avg
                        vehicles[expectedSensorPass[i]]["maxSpeed"] = vehicles[
                            expectedSensorPass[i]]["maxSpeed"] + vehicles[
                                expectedSensorPass[i]]["speed"]
                        vehicles[
                            expectedSensorPass[i]]["sensorsPassed"] = vehicles[
                                expectedSensorPass[i]]["sensorsPassed"] + 1

                elif state and sensorState[
                        i] == 1:  # Vehicle is still passing the sensor
                    sensorState[i] = 1
                elif state == 0 and sensorState[
                        i] == 1:  # Vehicle has finished passing the sensor
                    sensorState[i] = 0
            #pass and receive data

            #creates cycle if multiple PIs does not exist
            passToLeadingPi = PassToLeadingPiSend(passToLeadingPi,
                                                  receiveFromTrailingPi)
            passToTrailingPi = PassToTrailingPiSend(receiveFromLeadingPi,
                                                    passToTrailingPi)

            # PI to PI communication
            # receiveFromLeadingPi.setData(ast.literal_eval(clientStart.rec()))
            # receiveFromTrailingPi.setData(ast.literal_eval(clientEnd.rec()))
            # serverEnd.send(passToLeadingPi.getData())
            # serverStart.send(passToTrailingPi.getData())
            #reset pi to transfer data
            passToLeadingPi = PassToLeadingPi()
            passToTrailingPi = PassToTrailingPi()

            #turn on lights
            #print(LEDsStateNew)
            stepThrough(LEDsStateNew, LEDsDistance, LEDsNum, vehicles,
                        passToTrailingPi, passToLeadingPi, dataModel)
            updateStateFromNew(LEDsState, LEDsStateNew, LEDsNum)
            timeAtLEDUpdate = time.clock()
            LEDsModel = updateLEDsModel(LEDsModel,
                                        timeAtLEDUpdate - timeBeforeLEDUpdate,
                                        LEDsState)
            timeBeforeLEDUpdate = timeAtLEDUpdate
            turnOnLEDs(LEDsState, LEDsNum, LEDS)

            # Push data to firebase if the minute changes
            now = datetime.datetime.now()
            if now.minute > min:
                # resetdata
                secChanged = 0
                sec = now.second

                #calculate avgspeed
                noOfCars = 0
                avgSpeed = 0
                maxSpeed = 0
                for i in range(0, len(vehicles)):
                    print(vehicles[i]["maxSpeed"])
                    print(vehicles[i]["sensorsPassed"])
                    vehicles[i]["avgSpeed"] = vehicles[i]["maxSpeed"] / (
                        vehicles[i]["sensorsPassed"] + 1
                    )  #* # avg speed of that vehicle
                    maxSpeed = maxSpeed + vehicles[i][
                        "avgSpeed"]  #add average speed of all vehicles
                avgSpeed = maxSpeed / dataModel[
                    "numOfNewCars"]  #calculate avg speed of all new vehicles
                #reset vehicles data for next minute
                for i in range(0, len(vehicles)):
                    vehicles[i]["avgSpeed"] = 0
                    vehicles[i]["maxSpeed"] = 0
                    vehicles[i]["sensorsPassed"] = 0

                #append avgspeed
                dataModel["avgSpeed"] = avgSpeed
                dataModel["LEDsTurnedOn"] = LEDsModel
                #pushData(dataModel)
                t1 = threading.Thread(target=pushData, args=(dataModel, ))
                t1.start()

                #print dataModel
                print(dataModel)

                #reset data
                dataModel = dataModelInit
                LEDsModel = genLEDsFirebaseModel(LEDsNum)
                dataModel["LEDsTurnedOn"] = LEDsModel

    except KeyboardInterrupt:
        run = False
    finally:
        GPIO.cleanup()
Ejemplo n.º 19
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
Ejemplo n.º 20
0
    def _thread_func(self):
        current_time_ratio = 0.0  # How far into the timeslots we currently are, from 0 to 1
        time_ratio_advance = 1.0 / self.PWM_TIMESLOTS

        while time.sleep(self.SLEEP_DELAY):
            # Set LEDs to appropriate values
            for seg in range(LED_NUM_SEGS):
                for color in LED_COLORS:
                    # IMPORTANT: Implicitly dictates pin order for LEDs after shift register below
                    if self.state[seg][color] > current_time_ratio:
                        # Push a high on the shift register
                        GPIO.output(DATA_PIN, GPIO.high)
                        time.sleep(self.TRIGGER_DELAY)
                        GPIO.output(LATCH_PIN, GPIO.high)
                        time.sleep(self.TRIGGER_DELAY)
                        GPIO.output(LATCH_PIN, GPIO.low)
                        time.sleep(self.TRIGGER_DELAY)
                        GPIO.output(DATA_PIN, GPIO.low)
                    else:
                        # Push a low on the shift register
                        GPIO.output(DATA_PIN, GPIO.low)
                        time.sleep(self.TRIGGER_DELAY)
                        GPIO.output(LATCH_PIN, GPIO.high)
                        time.sleep(self.TRIGGER_DELAY)
                        GPIO.output(LATCH_PIN, GPIO.low)
                        time.sleep(self.TRIGGER_DELAY)
                        GPIO.output(DATA_PIN, GPIO.low)

            # Push updated states out to LED strip
            time.sleep(self.TRIGGER_DELAY)
            GPIO.output(PUSH_OUT_PIN, GPIO.high)
            time.sleep(self.TRIGGER_DELAY)
            GPIO.output(PUSH_OUT_PIN, GPIO.low)

            # Increment segment, resetting upon reaching 1 to 0
            current_time_ratio += time_ratio_advance
            if current_time_ratio == 1.0:
                current_time_ratio = 0.0
Ejemplo n.º 21
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
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
def turnOffSoda2():
    GPIO.output(soda_2, True)
Ejemplo n.º 24
0
def setGPIOIn(sensors):
    for i in range(0, len(sensors)):
        GPIO.setup(sensors[i], GPIO.IN)
Ejemplo n.º 25
0
def setGPIOOut(LEDS):
    for i in range(0, len(LEDS)):
        GPIO.setup(LEDS[i], GPIO.OUT)
Ejemplo n.º 26
0
def control(pin, action):
    contract_instance = w3.eth.contract(abi=abi,
                                        address=contract_address,
                                        ContractFactoryClass=ConciseContract)

    if pin == 'fourteen':
        actuator = 14
    if pin == 'fifteen':
        actuator = 15
    if pin == 'eighteen':
        actuator = 18
    if pin == 'twentythree':
        actuator = 23
    if pin == 'twentyfour':
        actuator = 24
    if pin == 'twentyfive':
        actuator = 25
    if pin == 'eight':
        actuator = 8
    if pin == 'seven':
        actuator = 7
    if pin == 'twelve':
        actuator = 12
    if pin == 'sixteen':
        actuator = 16
    if pin == 'twenty':
        actuator = 20
    if pin == 'twentyone':
        actuator = 21
    if pin == 'two':
        actuator = 2
    if pin == 'three':
        actuator = 3
    if pin == 'four':
        actuator = 4
    if pin == 'seventeen':
        actuator = 17
    if pin == 'twentyseven':
        actuator = 27
    if pin == 'twentytwo':
        actuator = 22
    if pin == 'ten':
        actuator = 10
    if pin == 'nine':
        actuator = 9
    if pin == 'eleven':
        actuator = 11
    if pin == 'five':
        actuator = 5
    if pin == 'six':
        actuator = 6
    if pin == 'thirteen':
        actuator = 13
    if pin == 'nineteen':
        actuator = 19
    if pin == 'twentysix':
        actuator = 26

    if action == 'on':
        config = 1
    if action == 'off':
        config = 0
    contract_instance.control(actuator,
                              config,
                              transact={'from': w3.eth.accounts[0]})
    print("Transaction its Way..")
    y = format(contract_instance.pinStatus(actuator))
    print(y)
    if y == "1":
        GPIO.output(actuator, GPIO.HIGH)
    else:
        GPIO.output(actuator, GPIO.LOW)
    templateData = {'title': "GPIO Control"}
    return render_template('index.html', **templateData)
Ejemplo n.º 27
0
def lighton(LEDS, i):
    GPIO.output(LEDS[i], GPIO.HIGH)
Ejemplo n.º 28
0
##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)
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
def makeGrogg3():

    GPIO.output(liquor_3, False)
    sprit = Timer(1.9, turnOffBooze3)

    sprit.start()