Skip to content

Instantly share code, notes, and snippets.

@fermuch
Created August 23, 2011 10:05
Show Gist options
  • Save fermuch/1164776 to your computer and use it in GitHub Desktop.
Save fermuch/1164776 to your computer and use it in GitHub Desktop.
Arduino Test
# -*- coding: utf-8 -*-
import sys
import time
from commands import getoutput
from arduino import Arduino
out = getoutput("ls /dev/ | grep -i ttyUSB").split()
try:
out[0]
print "Utilizando dispositivo: %s" % (out[0])
boardDev = out[0]
except IndexError:
print "No se pudo encontrar ningún dispositivo utilizable"
sys.exit()
board = Arduino(boardDev)
pin = 11
i = 0
ilimit = 100 # total de impresiones necesarias
try:
#while(True):
while(i<ilimit):
print board.analogRead(pin)
time.sleep(1)
i+=1
if (i == ilimit):
Arduino.close()
except KeyboardInterrupt:
Arduino.close()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment