def set_move_stop():
    # Set left wheel and right wheel to no direction
    gpio.output(pins.LEFT_CW, False)
    gpio.output(pins.LEFT_CCW, False)
    gpio.output(pins.RIGHT_CW, False)
    gpio.output(pins.RIGHT_CCW, False)

    # Set both motors to 0% duty cycle
    LEFT_WHEEL.ChangeDutyCycle(0)
    RIGHT_WHEEL.ChangeDutyCycle(0)
def set_move_reverse():
    # Set left wheel counterclockwise, right wheel clockwise
    gpio.output(pins.LEFT_CW, False)
    gpio.output(pins.LEFT_CCW, True)
    gpio.output(pins.RIGHT_CW, True)
    gpio.output(pins.RIGHT_CCW, False)

    # Set both motors running at 100% duty cycle
    LEFT_WHEEL.ChangeDutyCycle(100)
    RIGHT_WHEEL.ChangeDutyCycle(100)
def set_turn_right():
    # Set left wheel and right wheel to counterclockwise
    gpio.output(pins.LEFT_CW, False)
    gpio.output(pins.LEFT_CCW, True)
    gpio.output(pins.RIGHT_CW, False)
    gpio.output(pins.RIGHT_CCW, True)

    # Set both motors to 50% duty cycle
    LEFT_WHEEL.ChangeDutyCycle(50)
    RIGHT_WHEEL.ChangeDutyCycle(50)

    # Delay then turn off wheels
    time.sleep(TURN_DELAY)
    set_move_stop()
import time
import paho.mqtt.client as mqtt
import RPi.gpio as gpio
pir = 23
gpio.setmode(gpio.BCM)
gpio.setup(pir, gpio.IN)
client = mqtt.Client()
broker = "broker.hivemq.com"
port = 1883
pub_topic = "IntruderDetector_Home"


def SendData():
    client.publish(pub_topic, "WARNING : SOMEONE DETECTED AT YOUR PLACE")


def on_connect(client, userdata, flag, rc):
    print("connection returned" + str(rc))
    SendData()


while True:
    client.connect(broker, port)
    client.on_connect = on_connect
    if gpio.output(pir) == gpio.HIGH:
        SendData()
    client.loop_forever()
Exemplo n.º 5
0
# Variable setup
finished = False
left_lsw, right_lsw = False, False


def get_lsw_inputs():
    left_lsw = gpio.input(pins.LSW_ONE)
    right_lsw = gpio.input(pins.LSW_TWO)


while not finished:
    if not gpio.input(pins.BTN_START):
        continue
    else:
        # Start brushes
        gpio.output(pins.BRUSH_ONE, True)
        gpio.output(pins.BRUSH_TWO, True)

        # Start water pump
        gpio.output(pins.SOL_WATER, True)
        time.sleep(1)
        gpio.output(pins.PUMP_WATER, True)

        # Add a short delay to make sure it works
        time.sleep(1)

        get_lsw_inputs()
        movement.set_move_forward()
        while not (left_lsw or right_lsw):
            get_lsw_inputs()
        else:
Exemplo n.º 6
0
gpio.setup(18, gpio.OUT)
gpio.setup(21, gpio.OUT)
gpio.setup(23, gpio.OUT)
gpio.setup(26, gpio.OUT)

# secondary input pins to all motors in order from 1 to 8.
gpio.setup(5, gpio.OUT)
gpio.setup(11, gpio.OUT)
gpio.setup(13, gpio.OUT)
gpio.setup(16, gpio.OUT)
gpio.setup(19, gpio.OUT)
gpio.setup(22, gpio.OUT)
gpio.setup(24, gpio.OUT)
gpio.setup(29, gpio.OUT)

gpio.output(3, False)
gpio.output(5, False)
gpio.output(7, False)
gpio.output(11, False)
gpio.output(12, False)
gpio.output(13, False)
gpio.output(15, False)
gpio.output(16, False)
gpio.output(18, False)
gpio.output(19, False)
gpio.output(21, False)
gpio.output(22, False)
gpio.output(23, False)
gpio.output(24, False)
gpio.output(26, False)
gpio.output(29, False)