attiny light sculpture project - part ii (multileds)

4
Name: _______________________________ Date: ___________ Build your own ATTiny Light Sculpture! Part II Introduction In our first activity, we only used a single LED. The LED was already on the programmer. In this activity, we will look at hooking up several LEDs (5 of them) to our ATTiny85. LEDs are everywhere! They’re wonderful, amazing, semiconductor devices that emit light without heating a filament or a gas. It’s a very cool invention that uses the properties of elements, electrons, and a thing called band gaps. LEDs each come in a variety of colors -- each one very unique. The LED itself is very, very small. Most of what you’re looking at is just a piece of plastic. Notice that one leg of the LED is longer than the other? Make sure you remember which side is positive and which side is negative. Code Example Here is a real quick and simple code example to get you blinking all 5 LEDs. This code should look familiar to the first example. Here we’re just adding code to control the other 4 pins. (Remember: The code requires special punctuation marks and is case-sensitive.) void setup() { // The 8-pin ATTiny85 has 5 usable digital output pins 0 - 4 pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); } learn.sparkfun.com

Upload: brian-huang

Post on 24-Jan-2018

377 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: ATTiny Light Sculpture Project - Part II (MultiLEDs)

Name: _______________________________ Date: ___________

Build your own ATTiny Light Sculpture! Part II

Introduction In our first activity, we only used a single LED. The LED was already on the programmer. In this activity, we will look at hooking up several LEDs (5 of them) to our ATTiny85. LEDs are everywhere! They’re wonderful, amazing, semiconductor devices that emit light without heating a filament or a gas. It’s a very cool invention that uses the properties of elements, electrons, and a thing called band gaps. LEDs each come in a variety of colors -- each one very unique. The LED itself is very, very small. Most of what you’re looking at is just a piece of plastic. Notice that one leg of the LED is longer than the other? Make sure you remember which side is positive and which side is negative.

Code Example Here is a real quick and simple code example to get you blinking all 5 LEDs. This code should look familiar to the first example. Here we’re just adding code to control the other 4 pins. (Remember: The code requires special punctuation marks and is case-sensitive.)

void setup() {

// The 8-pin ATTiny85 has 5 usable digital output pins 0 - 4

pinMode(0, OUTPUT); pinMode(1, OUTPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT);

}

learn.sparkfun.com

Page 2: ATTiny Light Sculpture Project - Part II (MultiLEDs)

void loop() {

// Set the LED pins to HIGH. Turns LEDs on!

digitalWrite(0, HIGH); digitalWrite(1, HIGH); digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH);

delay(500); // Wait for 1/2 a second

//Set the LED pins to LOW. This turns them off

digitalWrite(0, LOW); digitalWrite(1, LOW); digitalWrite(2, LOW); digitalWrite(3, LOW); digitalWrite(4, LOW);

delay(500); // Wait for 1/2 a second }

Plug your ATTiny85 chip into your programmer and click upload to compile and upload this code. Double check to make sure that you have ATTiny85 (1 MHz) selected under Boards and that you have the Programmer set to USBTinyISP. If you get any syntax errors, double-check your typing. Once you get a message that says “Done Uploading” -- let’s look at how we will wire up your circuit.

Solderless BreadBoard To do our wiring, we are going to use a tool called a solderless breadboard. Notice how there are a set of repeating rows of 5 holes on the breadboard? Rather than twisting wires together or soldering them, we can simply plug wires into these holes to connect them together. Each row of 5 holes is connected internally by a metal clip. Pay attention to which wires need to connect to which pins / components.

learn.sparkfun.com 2

Page 3: ATTiny Light Sculpture Project - Part II (MultiLEDs)

Wiring Diagram Use the diagram below to guide you through the wiring. Move the ATTiny85 chip to this board so that it straddles the center of the breadboard. Any wires that you plug into the right side will connect to the right side pins and any wires connected to the left side will connect to the left side pins. Make sure that if you have two wires you intend on connecting that they are both on the same row. The chip needs to be powered. Connect the positive of the battery (+) to the upper right corner pin of the chip and negative side (-) to the lower left corner. For each LED, there is a long leg and a short leg. Remember that the short leg should always connect to Ground (-). Follow the schematic drawing or the pictorial drawing below for reference.

If your chip is programmed up, and the wiring is correct, you should see all 5 LEDs blinking ON and OFF. Do you?

If your circuit didn’t work the first time, what did you have to fix? How did you figure this out?

learn.sparkfun.com 3

Page 4: ATTiny Light Sculpture Project - Part II (MultiLEDs)

Challenge B 1) LED Chaser. Modify the code so that the LEDs turn on one at a time with at least

1/10 of a second before the next LED turns on. Now, modify it so that the LEDs also turn off one at a time.

2) Ping Pong. Write a program so that only a single LED is on at a time. Make it look like the LED is bouncing back and forth from left to right.

3) Maker’s Choice. Design your own pattern and then code it up. Make sure that you

spend time “designing” and not just randomly throwing things together. Draw, explain, or write-out your design idea here before writing any code. Be Creative! Use extension wires to move the LEDs off from the breadboard. Add glue sticks, plastic cups, construction paper, or any other craft materials to build your very own light sculpture!

learn.sparkfun.com 4