Hey guys,
I'm trying to write a simple program using PySerial.
I have two servos and two touch sensors.
I want to write something so that when I touch each sensor, the corresponding servo would move.
I've managed to set up PySerial, and even control a Servo with it. My main problem is reading the touch sensors when they are touched, AND discerning which touch sensor is being touched.
Here's my Python code if you're interested. (This basically takes in a number as input and sends it to the Arduino. The Arduino moves the Servo according to this number).
import serial as Serial
def main():
serial = Serial.Serial('/dev/tty.usbmodem621', 9600)
char = 't'
while char != 'e':
char = raw_input( '> ' )
numb = int( char )
numb_ascii = chr( numb )
char = numb_ascii
if char == 'e':
break;
serial.write( char )
print "->", serial.readline().rstrip( '\r' ).rstrip( '\n' )
serial.close()
if __name__ == '__main__':
main()
Would greatly appreciate your help. Thanks guys.