Make Them Blink

2587 0

You will need:

4 complete sets of LED’s and wires (see last lesson)

The first thing you will need to is connect your negative sides of the wire to any ground cable that is not taken, like 14, 9, 20, or 25.

The next thing you will need to do is to connect the positive sides of the LED(s) to 11, 12, 13, and 33.(pleas see chart)

What you will need to do next is to open a new file in text editor.

The first thing you will need to type is your shebang line.

The next thing you will need is to create a variable, a variable is a name assigned to mean a number or thing or a … anything. For example (Fish = .05). Fish is an example, you would usually say what its doing in a short way, we need the amount of time to blink… blinkTime. after that you put  = 1.

That kind of variable is called a scalar variable, a variable with one name.

sometimes we need a variable that means a list of things, an array variable.

We need to make a list of the Gpio pin numbers that we are going to blink. Those are pin numbers 11, 12, 13, and 33.Those numbers represent the positive wires we are using. An array is enclosed in square brackets []. If i made an array of my three favorite coolers, it would be [“green”,”black”,”blue”] –Two things to note:

  1. In an array valus in the list are separated by commas
  2. If a variable is a phrase or a word, it must be contained in quotes, if its a number, no quotes.

For are code we need to make a variable called blinkPins, and then the array.

Next we need to be able to control the GPIO with python, also you need time functions.

Just like last time

Now lets use are array for something fun:

the “for” command – the for command does the same thing over and over again for each item in an array. The for command assigns a special variable that changes for each item in an array list. Last time we set up a single pin on our GPIO, this time we will set up four of them with our array.

The first time our for loop runs, it will use the first number on our list, 11. it will then run 12, then 13, then 33. If we wrote this out in code without an array or without for, it would take at least four times as much code.

so lets type in our first “for” loop:

Above we say for p in blinkPins, p will be the variable for each item in the blinkPins array. The lines that start with a tab is the lines that will repeat until for has finished with our array.


“GPIO.setup(p, GPIO.OUT)”is the same command we ran last time, but this time it will run four all for of our blinking pins, and not just once.

To finish up and just like the first loop we will link through blink pins again. The first command inside our second loop will turn on the power to the LED bulb each time then, the time sleep command will sleep for the number of seconds in blinkTime, or 1 second. Then, we turn the LED off again, and wait one more second before going to the next step of the loop or finishing.

Lastly, you tell, python to stop using GPIO so other prosseces can run if you leave this out you will get an error next time you run it.


Related Post

while loop

Posted by - October 18, 2015 0
[crayon-66228db33a1f4299311984/] Keep Reading : Pi Camera Resolution Fix Hello World LED Blinking Wire camera to pi


Posted by - November 22, 2015 0
SMS on your Raspberry Pi… Adapted from : This assumes you have set up your sim card, wired your…

GPS AT Commands

Posted by - October 18, 2015 0
AT+CGPSPWR? if off : AT+CGPSPWR=1 Get status : AT+CGPSSTATUS? Get GPS : AT+CGPSINF RESET CODES : What mode ? –…


Posted by - October 18, 2015 0
in response to AT+CGPSINF=0 0 longitude 1 latitude 2 altitude 3 UTC Broadcast Time 4 TTFF Time To First Fix…

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.