def loop():
    loop_exit = 1
    toggle = 0
    forward = 0
    leftright = 0
    leftinp = 0
    rightinp = 0
    while loop_exit:
        GPIO.output(M1, GPIO.LOW)
        GPIO.output(M2, GPIO.LOW)
        forward = ADC0832_tmp.getResult1()
        if (forward > 125):
            forward = 0
        else:
            forward = 125 - forward
        leftright = ADC0832_tmp.getResult() - 5
        if (leftright < 0):
            leftright = 0
        if (leftright >= 125):
            leftinp = 125
            rightinp = 125 - (leftright - 125)
        else: # if leftright < 125
            leftinp = leftright
            rightinp = 125
        print "leftright = " + str(leftright) + " " + str(forward) + " -> " + str((float(forward) / 125))
        leftinp = (int((float(forward) / 125) * leftinp * 2 + 0.5)) / 25
        rightinp = (int((float(forward) / 125) * rightinp * 2 + 0.5)) / 25
        if (GPIO.input(btn) == 0):
            loop_exit = 0;
        else:
            pwm(leftinp, rightinp)
Пример #2
0
def setup():
    ADC0832_tmp.setup()
    GPIO.setmode(GPIO.BOARD)  # Numbers pins by physical location
    GPIO.setwarnings(False)
    GPIO.setup(LedPin, GPIO.OUT)  # Set pin mode as output
    GPIO.setup(FanPin, GPIO.OUT)
    GPIO.setup(MainLightPin, GPIO.OUT)
    GPIO.output(LedPin, GPIO.LOW)  # Set pin to high(+3.3V) to off the led
def setup():
    ADC0832_tmp.setup()  # setup ADC0832
    GPIO.setmode(GPIO.BOARD)  # numbers GPIOs by physical location
    GPIO.setup(btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)  # setup button pin as input an pull it up
    GPIO.setup(E1, GPIO.OUT)  # set up control pins as outputs
    GPIO.setup(M1, GPIO.OUT)
    GPIO.setup(E2, GPIO.OUT)
    GPIO.setup(M2, GPIO.OUT)
Пример #4
0
def setup():
    ADC0832_tmp.setup()  # Setup ADC0832
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(
        btn, GPIO.IN,
        pull_up_down=GPIO.PUD_UP)  # Setup button pin as input an pull it up
    global state
    state = ['up', 'down', 'left', 'right']
def result():
    if ADC0832_tmp.getResult1() == 0:
        return 1  # up
    if ADC0832_tmp.getResult1() == 255:
        return 2  # down
    if ADC0832_tmp.getResult() == 0:
        return 3  # left
    if ADC0832_tmp.getResult() == 255:
        return 4  # right
    if GPIO.input(btn) == 0:
        return 5  # button
    return 0
def getResult():	#get joystick result
	if ADC0832_tmp.getResult1() == 0:
		return 1		#up
	if ADC0832_tmp.getResult1() == 255:
		return 2		#down

	if ADC0832_tmp.getResult() == 0:
		return 3		#left
	if ADC0832_tmp.getResult() == 255:
		return 4		#right

	if GPIO.input(btn) == 0:
		print 'Button is pressed!'		# Button pressed
Пример #7
0
def getResult():  #get joystick result
    if ADC0832_tmp.getResult1() == 0:
        return 1  #up
    if ADC0832_tmp.getResult1() == 255:
        return 2  #down

    if ADC0832_tmp.getResult() == 0:
        return 3  #left
    if ADC0832_tmp.getResult() == 255:
        return 4  #right

    if GPIO.input(btn) == 0:
        print 'Button is pressed!'  # Button pressed
Пример #8
0
def setup():
    """ Setup Raspberry Pi """

    ADC0832_tmp.setup()  # Setup ADC0832
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(
        btn, GPIO.IN,
        pull_up_down=GPIO.PUD_UP)  # Setup button pin as input an pull it up
    GPIO.setup(16, GPIO.OUT)  # Servo Output pin
    global state
    state = ['up', 'down', 'left', 'right']
    p = GPIO.PWM(16, 50)  # Servo PWM pin
    p.start(7.5)
Пример #9
0
def getResult():
    """get joystick results """

    if ADC0832_tmp.getResult1() == 0:
        return 1  # up
    if ADC0832_tmp.getResult1() == 255:
        return 2  # down
    if ADC0832_tmp.getResult() == 0:
        servoguy()  # call servo myguy
        print('Servo Running!')
        return 3  # left, and servo starts to run
    if ADC0832_tmp.getResult() == 255:
        servoguy()
        print('Servo Running!')
        return 4  # right, and servo starts to run
    if GPIO.input(btn) == 0:
        print 'Button is pressed!'  # Button pressed
Пример #10
0
def loop():
    while True:
        sig = ADC0832_tmp.getResult(0)
        GPIO.cleanup()
        lcd = lcd1602.Adafruit_CharLCD()
        lcd.clear()
        lcd.message("Soil moisture :")
        lcd.message(str(sig))
        time.sleep(1.0)
Пример #11
0
def loop():
    while True:
        currenttime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        res = ADC0832_tmp.getResult() - 80
        if res < 0:
            res = 0
        if res > 100:
            res = 100
        print "Time: " + currenttime
        print 'Sunlight = %d' % res
        res1 = ADC0832_tmp.getResult1()
        moisture = 255 - res1
        print 'Soil moisture: %d' %(moisture)
        readSensors()
        print "G Temperature : %0.3f C" % g_temperature
        distance = ADC0832_tmp.checkdist()
        print 'Distance: %0.2f m' % distance

		
		
        client.publish("sensors",currenttime + "," + str(res)+","+str(moisture)+","+str(g_temperature)+","+str(distance))
        time.sleep(5)
def setup():
	ADC0832_tmp.setup()				# Setup ADC0832
	GPIO.setmode(GPIO.BOARD)	# Numbers GPIOs by physical location
	GPIO.setup(btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)	# Setup button pin as input an pull it up
	global state
	state = ['up', 'down', 'left', 'right']	
Пример #13
0
def loop():
    while True:
        sig = ADC0832_tmp.getResult(0)
        GPIO.cleanup()
        lcd = lcd1602.Adafruit_CharLCD()
        lcd.clear()
        lcd.message("Soil moisture :")
        lcd.message(str(sig))
        time.sleep(1.0)


if (__name__ == '__main__'):
    setup()
    try:
        sig = ADC0832_tmp.getResult(0)
        GPIO.cleanup()

        lcd = lcd1602.Adafruit_CharLCD()
        lcd.clear()
        lcd.message("Soil moisture :")
        lcd.message(str(sig))

    except KeyboardInterrupt:
        end()

#GPIO SETUP
# channel = 37
# GPIO.setmode(GPIO.BOARD)
# GPIO.setup(channel, GPIO.IN)
Пример #14
0
            res = 0
        if res > 100:
            res = 100
        print "Time: " + currenttime
        print 'Sunlight = %d' % res
        res1 = ADC0832_tmp.getResult1()
        moisture = 255 - res1
        print 'Soil moisture: %d' %(moisture)
        readSensors()
        print "G Temperature : %0.3f C" % g_temperature
        distance = ADC0832_tmp.checkdist()
        print 'Distance: %0.2f m' % distance

		
		
        client.publish("sensors",currenttime + "," + str(res)+","+str(moisture)+","+str(g_temperature)+","+str(distance))
        time.sleep(5)

# Nothing to cleanup
def destroy():
    pass
	
if __name__ == '__main__':
    init()
    try:
        loop()
    except KeyboardInterrupt: 
        ADC0832_tmp.destroy()
        destroy()
        print 'The end !'