Materials:
-1 Raspberry Pi
-2 LEDs
-2 Resistors (1kΩ)
-Wires
To do that, first, we have to connect a LED and a resistor to the pins 17 and 27 of the Raspberry Pi. The end of the circuit will be in a pin of GND, also in our Raspberry Pi. We can mount it in a protoboard.
In the Raspberry Pi, we will open Python3 and we will write this code:
import RPi.GPIO as GPIO //Here, we import the library GPIO to be able to use the ports GPIO of the Raspberry Pi.
import time //Here, we import the library time, to be able to use timing in the Raspberry Pi
GPIO.setmode(GPIO.BCM) //Here, we say to the raspberry that we will use BCM to call the input and output ports
GPIO.setup(17,GPIO.OUT) //Here, we stablish the port 17 as an output
GPIO.setup(27,GPIO.OUT) //Here, we stablish the port 27 as an output
def blink(): //In this part of the program, we will define the function blink, due to that we will do this program doing a call to a function
print ('Ejecucion iniciada...') //We say on the screen that the program has started
iteracion=0 //We initializate the variable iteration as 0
while iteracion<30: //We start a while loop, that will finish when the variable iteracion be over 30
GPIO.output(17,True) //We will say here that the output of the pin 17 is TRUE
GPIO.output(27,False) //We will say here that the output of the pin 27 is FALSE
time.sleep(1) //We will do a delay of 1 second
GPIO.output(17,False) //We will say here that the output of the pin 17 is FALSE
GPIO.output(27,True) //We will say here that the output of the pin 27 is TRUE
time.sleep(1) //Here, we will do a delay of 1 second
iteracion=iteracion+2 //We will increase the variable iteracion
print('Ejecucion finalizada') //Once the program has finished, we will say it on the screen
GPIO.cleanup() //Then, we will close the ports to avoid problems
blink() //This is the program, where we only call the function called blink
And this is all the practice, it's very simple. If you want, you can download the program from here:
https://drive.google.com/folderview?id=0B20kHfrc3NnpTkszRUNvMF9nX1E&usp=sharing
https://drive.google.com/folderview?id=0B20kHfrc3NnpTkszRUNvMF9nX1E&usp=sharing
No hay comentarios:
Publicar un comentario