ebsigma
Posts: 79
Joined: Sat Aug 11, 2012 10:33 am

error en codigo copiado para 2leds 1 pin

Thu Jan 21, 2016 7:24 am

el caso es que siguiendo el tutorial: http://www.instructables.com/id/Charlie ... ?ALLSTEPS
copio el codigo siguiente y me da error en la linea 15 #Now setup the first pin for HIGH OUTPUT
gpio.setup(led[0],gpio.OUT) impidiendome continuar, como no se mucho de python no se que falla...

Code: Select all

# Import the module that runs the GPIO pins
import RPi.GPIO as gpio

# Import the sleep function for pausing
from time import sleep

# Import the random integer function
from random import randint

# This fuction lights a specif LED.
# The led variable input is a 2 item list,
# each item representing a pin
def lightLED(led):
	#First clear the pins, by setting them all to input
	for pin in charliePins:
		gpio.setup(pin,gpio.IN)
	
	#Now setup the first pin for HIGH OUTPUT
    gpio.setup(led[0],gpio.OUT)
    gpio.output(led[0],gpio.HIGH)
	
	#Now setup the second pin for LOW OUTPUT
    gpio.setup(led[1],gpio.OUT)
    gpio.output(led[1],gpio.LOW)

# define an array of pins used as leads
charliePins=[7,11,12]

# Define the top and bottom rows as the number of the 
# LED in the list of LEDs to be created.
top=[0,2,4]
bottom=[1,3,5]

# Define the array of LEDs.  This is normally done
# by defining each pair separately, but I wanted the code
# to be easy to expand, so I went with this method of
# cycling through the pins and creating the pairs.  It
# has the disadvantage of not making them in order for larger
# sets of pairs, but is easier to maintain, IMO.
charlieLEDS=[]
for i in range(0,len(charliePins)-1):
    for j in range(i+1,len(charliePins)):
            charlieLEDS.append([charliePins[i],charliePins[j]])
            charlieLEDS.append([charliePins[j],charliePins[i]])

# setup the GPIO pins to BOARD mode
gpio.setmode(gpio.BOARD)

#Run the code over and over and over again
while 1:
	# First light them in order
    for led in charlieLEDS:
        lightLED(led)
        sleep(.25)

	# Next flash the top and bottom rows
	for flash in range(0,6):
        for light in range(0,100):
            for led in top:
                lightLED(charlieLEDS[led])
                sleep(.001)
        for light in range(0,100):
            for led in bottom:
                lightLED(charlieLEDS[led])
                sleep(.001)
				
	# Finally, flash them randomly
    for counter in range(0,26):
        lightLED(charlieLEDS[randint(0,5)
        sleep(.1)

User avatar
actkk2000
Posts: 1309
Joined: Wed Apr 02, 2014 3:22 am

Re: error en codigo copiado para 2leds 1 pin

Thu Jan 21, 2016 12:50 pm

Me parece que es el espaciado en la función "lightLED", la alineación de las sentencias no se mantiene.
Deberias probar :

Code: Select all

def lightLED(led):
   #First clear the pins, by setting them all to input
   for pin in charliePins:
      gpio.setup(pin,gpio.IN)
   
   #Now setup the first pin for HIGH OUTPUT
      gpio.setup(led[0],gpio.OUT)
      gpio.output(led[0],gpio.HIGH)
   
   #Now setup the second pin for LOW OUTPUT
      gpio.setup(led[1],gpio.OUT)
      gpio.output(led[1],gpio.LOW)
Slds!
Robot +Camara +Sensores +Encoder +Servo +Matriz8x8 +Joystick:
https://www.raspberrypi.org/forums/viewtopic.php?f=76&t=130470

ebsigma
Posts: 79
Joined: Sat Aug 11, 2012 10:33 am

Re: error en codigo copiado para 2leds 1 pin

Sat Jan 23, 2016 9:45 am

ahora el error me ocurre en:

Code: Select all

while 1:
        # First light them in order
    for led in charlieLEDS:
        lightLED(led)
        sleep(.25)

        # Next flash the top and bottom rows
        for flash in range(0,6):
        for light in range(0,100):
            for led in top:
                lightLED(charlieLEDS[led])
                sleep(.001)
        for light in range(0,100):
            for led in bottom:
                lightLED(charlieLEDS[led])
                sleep(.001)

        # Finally, flash them randomly
    for counter in range(0,26):
        lightLED(charlieLEDS[randint(0,5)
        sleep(.1)
# Next flash the top and bottom rows
for flash in range(0,6):
for light in range(0,100):
for led in top:
lightLED(charlieLEDS[led])

lo he desplazao un espacio los in range 0,100 y al final el error me da en sintaxis al final
sleep(.1)

User avatar
actkk2000
Posts: 1309
Joined: Wed Apr 02, 2014 3:22 am

Re: error en codigo copiado para 2leds 1 pin

Sat Jan 23, 2016 3:00 pm

Me parece que es el espaciado en la línea de "0,6" que estaba mal alineado:

Code: Select all

while 1:
	# First light them in order
    for led in charlieLEDS:
        lightLED(led)
        sleep(.25)

	# Next flash the top and bottom rows
    for flash in range(0,6):
        for light in range(0,100):
            for led in top:
                lightLED(charlieLEDS[led])
                sleep(.001)
        for light in range(0,100):
            for led in bottom:
                lightLED(charlieLEDS[led])
                sleep(.001)
				
	# Finally, flash them randomly
	# NOTE: We've change the code to randomly flash
	# The LEDs based on the number of LEDs automatically
    for counter in range(0,26):
        lightLED(charlieLEDS[randint(0,len(charlieLEDS)-1)
        sleep(.1)
Slds!
Robot +Camara +Sensores +Encoder +Servo +Matriz8x8 +Joystick:
https://www.raspberrypi.org/forums/viewtopic.php?f=76&t=130470

ebsigma
Posts: 79
Joined: Sat Aug 11, 2012 10:33 am

Re: error en codigo copiado para 2leds 1 pin

Sun Jan 24, 2016 10:53 am

su bueno ya lo solucione pero me sale error ahora al final el error me da en sintaxis al final
sleep(.1)
lo cual no entiendo ya que anteriormente hay sleep y no da error...

User avatar
actkk2000
Posts: 1309
Joined: Wed Apr 02, 2014 3:22 am

Re: error en codigo copiado para 2leds 1 pin

Sun Jan 24, 2016 2:32 pm

Prueba poner

Code: Select all

sleep(0.1)
Slds!
Robot +Camara +Sensores +Encoder +Servo +Matriz8x8 +Joystick:
https://www.raspberrypi.org/forums/viewtopic.php?f=76&t=130470

Return to “Español”