Make Them Blink

734 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.

IMG_3044

“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.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Related Post

Serial Commands used by our Satellite transciever.

Posted by - October 17, 2015 0
We will need the crc16 python code library : http://code.google.com/p/pycrc16/downloads [crayon-59c360509e8bc539229808/] [crayon-59c360509e8db799040215/]   [crayon-59c360509e8ec150943872/] Keep Reading : Serial Communication with…

Turn string into array with split

Posted by - October 18, 2015 0
textWithCommas = “bee,apple,pear,dog,carrot,robot” wordList = textWithCommas.split(“,”) print “the second item is : ” + textWithCommas[1] Keep Reading : Identify USB…

Phase One

Posted by - August 15, 2015 2
“Phase One” is where we learned basic raspberry pi use. we started with the unboxing of our model 2 B raspberry…

google map link

Posted by - October 18, 2015 0
http://www.google.com/maps/place/40.625027,-73.957774/@40.625027,-73.957774,17z Change RED part to current GPS in Python   http://maps.google.com/maps?q=40.37494164,-73.57485968   Keep Reading : GPS AT Commands GPS RESPONSE…

Leave a comment

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