Difference between revisions of "Digital for Arduino"

From LVL1
Jump to navigation Jump to search
Line 71: Line 71:
  
 
And the code specific to having A0 used instead of D6:
 
And the code specific to having A0 used instead of D6:
 +
<pre>
 +
//Code for Cylon - I am sure this could be more elegant!
 +
//bpw 2/11/22
 +
//modified for Pin A0 bpw 1/28/12
 +
 +
int pinled1 = 7;
 +
int pinled2 = 8;
 +
int pinled3 = 9;
 +
int pinled4 = 10;
 +
int pinled5 = 11;
 +
int pinled6 = 12;
 +
int pinled7 = 13;
 +
int pinled8 = 14;  //Pin 14 is the same as A0.  You can use A0 as a digital pin!
 +
int t = 50;
 +
void setup()
 +
{
 +
pinMode(pinled1, OUTPUT);
 +
pinMode(pinled2, OUTPUT);
 +
pinMode(pinled3, OUTPUT);
 +
pinMode(pinled4, OUTPUT);
 +
pinMode(pinled5, OUTPUT);
 +
pinMode(pinled6, OUTPUT);
 +
pinMode(pinled7, OUTPUT);
 +
pinMode(pinled8, OUTPUT);
 +
}
 +
 +
void loop()
 +
{
 +
digitalWrite(pinled1, HIGH);
 +
delay(t);
 +
digitalWrite(pinled2, HIGH);
 +
delay(t);
 +
digitalWrite(pinled1, LOW);
 +
delay(t);
 +
digitalWrite(pinled3, HIGH);
 +
delay(t);
 +
digitalWrite(pinled2, LOW);
 +
delay(t);
 +
digitalWrite(pinled4, HIGH);
 +
delay(t);
 +
digitalWrite(pinled3, LOW);
 +
delay(t);
 +
digitalWrite(pinled5, HIGH);
 +
delay(t);
 +
digitalWrite(pinled4, LOW);
 +
delay(t);
 +
digitalWrite(pinled6, HIGH);
 +
delay(t);
 +
digitalWrite(pinled5, LOW);
 +
delay(t);
 +
digitalWrite(pinled7, HIGH);
 +
delay(t);
 +
digitalWrite(pinled6, LOW);
 +
delay(t);
 +
digitalWrite(pinled8, HIGH);
 +
delay(t);
 +
digitalWrite(pinled7, LOW);
 +
delay(t);
 +
digitalWrite(pinled7, HIGH);
 +
delay(t);
 +
digitalWrite(pinled8, LOW);
 +
delay(t);
 +
digitalWrite(pinled6, HIGH);
 +
delay(t);
 +
digitalWrite(pinled7, LOW);
 +
delay(t);
 +
digitalWrite(pinled5, HIGH);
 +
delay(t);
 +
digitalWrite(pinled6, LOW);
 +
delay(t);
 +
digitalWrite(pinled4, HIGH);
 +
delay(t);
 +
digitalWrite(pinled5, LOW);
 +
delay(t);
 +
digitalWrite(pinled3, HIGH);
 +
delay(t);
 +
digitalWrite(pinled4, LOW);
 +
delay(t);
 +
digitalWrite(pinled2, HIGH);
 +
delay(t);
 +
digitalWrite(pinled3, LOW);
 +
delay(t);
 +
digitalWrite(pinled1, HIGH);
 +
delay(t);
 +
digitalWrite(pinled2, LOW);
 +
delay(t);
 +
 +
}
 +
 +
</pre>
  
 
== '''Part 4''' ==
 
== '''Part 4''' ==

Revision as of 16:07, 28 January 2012

Digital.png

Digital electronics for Arduino Workshop. Taught and designed by Brian Wagner.

SIGN UP HERE http://digitalarduino.eventbrite.com

We will build and program an electronic game and in the process learn LED's, tri-color LED's, pushbutton switches, speakers and Arduino programming.


You must bring your own Arduino or clone!


You will need to have an Arduino or an Arduino clone to participate in this workshop. They can be purchased online (but be aware of shipping times) or at a local Radio shack http://www.radioshack.com/product/index.jsp?productId=12268262 You will need to have a USB cable to connect to your computer.


Other Arduino retailers

Adafruit http://www.adafruit.com/products/50

Sparkfun http://www.sparkfun.com/products/9950

Solarbotics (Canada - can have slower shipping) http://www.solarbotics.com/products/28920/

Seeed studios http://www.seeedstudio.com/depot/seeeduino-v30-atmega-328p-p-669.html?cPath=132_133 Cheapest around, but they come from HK so they take a while to get.

Again, do not forget the USB cable

You can also use a serial based Arduino such as the Diavolina ($13!!!), but you need a $20 cable! http://evilmadscience.com/productsmenu/tinykitlist/180


You will also need to bring a laptop computer for programming your Arduino. We will show you how!


All other supplies are included in the cost of the workshop (wire, leds, switch, solderless breadboard, speaker, etc)


LVL1 has snacks and sodas available for purchase, but you can bring your own if you want.


Here is the Poster so you can print and hang in your favorite coffee shop. File:Digital.pdf


The Class

As we work through the parts below, do not remove the parts as you go. I have set this up so that by the end, the whole circuit game is built! I have taken parts of a couple of other classes to create this class. For the most part, the code is the same, but sometimes I had to rewire the circuit so the code has changed. I have posted the changes.

Part 1

Install the Arduino software and get your development system going. Be sure to run power and ground to the Arduino.

http://wiki.lvl1.org/1st_Inning


Part 2

Blinky Light - Get one LED blinking. This Blinkey light is hooked up to pin 13, but this is not the last light in the cylon lights, so please give room on your breadboard for one more LED to the left.

You can run the code in the Arduino development File->Examples->Basics->Blink. This blinking code is a very useful way to see if your Arduino is working. Some Arduino boards have a LED already installed to Pin D13 just for testing purposes.

http://wiki.lvl1.org/2nd_Inning

Part 3

Cylon lights - Battlestar Galactica or KITT from Knight Rider - take your pick. In this part we will use pin A0 instead of digital pin 6. I need the PWM capabilities of digital pin 6 for the tri-color LED. Pin A0 (as well as all the analog pins) can be used as digital pins. A0 can be thought of as D14.

Go ahead and build the circuit on the breadboard. You will want to keep the LEDS close to each other. I spaced them two columns apart from each other on the breadboard.

http://wiki.lvl1.org/Cylon_LEDs

And the code specific to having A0 used instead of D6:

//Code for Cylon - I am sure this could be more elegant!
//bpw 2/11/22
//modified for Pin A0 bpw 1/28/12

int pinled1 = 7; 
int pinled2 = 8; 
int pinled3 = 9;
int pinled4 = 10;
int pinled5 = 11;
int pinled6 = 12;
int pinled7 = 13;
int pinled8 = 14;  //Pin 14 is the same as A0.  You can use A0 as a digital pin!
int t = 50; 
void setup() 
{
pinMode(pinled1, OUTPUT);
pinMode(pinled2, OUTPUT);
pinMode(pinled3, OUTPUT);
pinMode(pinled4, OUTPUT);
pinMode(pinled5, OUTPUT);
pinMode(pinled6, OUTPUT);
pinMode(pinled7, OUTPUT);
pinMode(pinled8, OUTPUT);
}

void loop() 
{
digitalWrite(pinled1, HIGH); 
delay(t); 
digitalWrite(pinled2, HIGH);
delay(t);
digitalWrite(pinled1, LOW);
delay(t);
digitalWrite(pinled3, HIGH);
delay(t);
digitalWrite(pinled2, LOW);
delay(t);
digitalWrite(pinled4, HIGH);
delay(t);
digitalWrite(pinled3, LOW);
delay(t);
digitalWrite(pinled5, HIGH);
delay(t);
digitalWrite(pinled4, LOW);
delay(t);
digitalWrite(pinled6, HIGH);
delay(t);
digitalWrite(pinled5, LOW);
delay(t);
digitalWrite(pinled7, HIGH);
delay(t);
digitalWrite(pinled6, LOW);
delay(t);
digitalWrite(pinled8, HIGH);
delay(t);
digitalWrite(pinled7, LOW);
delay(t);
digitalWrite(pinled7, HIGH);
delay(t);
digitalWrite(pinled8, LOW);
delay(t);
digitalWrite(pinled6, HIGH);
delay(t);
digitalWrite(pinled7, LOW);
delay(t);
digitalWrite(pinled5, HIGH);
delay(t);
digitalWrite(pinled6, LOW);
delay(t);
digitalWrite(pinled4, HIGH);
delay(t);
digitalWrite(pinled5, LOW);
delay(t);
digitalWrite(pinled3, HIGH);
delay(t); 
digitalWrite(pinled4, LOW);
delay(t);
digitalWrite(pinled2, HIGH);
delay(t);
digitalWrite(pinled3, LOW);
delay(t);
digitalWrite(pinled1, HIGH);
delay(t);
digitalWrite(pinled2, LOW);
delay(t);

}

Part 4

Tri-Color LED

http://wiki.lvl1.org/3rd_Inning


Part 5

Push Button Switch

http://wiki.lvl1.org/5th_Inning



Part 6

Speaker - Lets make some noise

http://wiki.lvl1.org/9th_Inning


Part 7

Put it all together and make a game