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
Esempio n. 3
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
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)
Esempio n. 5
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
Esempio n. 6
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)