which led(s) turn on? · building an led cube: key tips plan ahead •read the entire handout first...

25
May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 1 Which LED(s) turn on?

Upload: others

Post on 13-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 1

Which LED(s) turn on?

Page 2: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Lab 3aThe LED cube

ENGR 40M

Chuan-Zheng Lee

Stanford University

5 May 2017

Page 3: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Outline

1. Hardware to make your LEDs work

2. Getting from an 8 × 8 array to a 4 × 4 × 4 cube

3. Tips for putting your cube together

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 5

Page 4: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Review: Pin multiplexing

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 6

an

od

es

cathodes

……

Page 5: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Where should we put the resistors?

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 7

an

od

es

cathodes

……

Page 6: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Where should we put the resistors?

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 8

cathodes

an

od

es

Page 7: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

How many LEDs could be on at once?

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 9

cathodes

an

od

es

Page 8: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

How many LEDs could be on at once?

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 10

If I want each LED, when on, to conduct 10 mA,

and all of the LEDs in a row are on, how much

current must pin D provide?

Page 9: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Providing enough current

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 11

from

Arduino

Use a PMOS to provide enough power to the LEDs

Page 10: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Putting it all together

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 12

Page 11: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Electrically it’s an array, but physically…

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 13

How do we

arrange these in a

4 × 4 × 4 cube?

Page 12: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

…it’s a cube?

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 14

Page 13: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

…it’s a cube?

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 15

bottom

second

from

bottom

second

from toptop

Page 14: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Mapping between 2-D and 3-D

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 16

Page 15: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Mapping between 2-D and 3-D

We want a function that maps

to anode/cathode pairs𝑎, 𝑐

(e.g. “D6”)

from 3D coordinates𝑥, 𝑦, 𝑧

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 17

Page 16: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Mapping between 2-D and 3-D

Anodes Cathodes

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 18

Page 17: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Mapping between 2-D and 3-D

Operations we might consider using:

• * (multiplication)

• % (modulo division)

• / (integer division)

• & (bitwise and)

• | (bitwise or)

• ^ (bitwise xor)

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 19

Page 18: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

What do bitwise operations do?

• Bitwise operations apply to each bit in the binary representation of a number individually

Examples (in binary):

00110101 | 01100011 == 01110111

00110101 & 01100011 == 00100001

00110101 00110101

| 01100011 & 01100011

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 20

Page 19: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Making the mapping function easier

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 21

You can reorder the anodes/cathodes however you like.

Would a different ordering make the relationship simpler?

Page 20: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Building an LED cube: Key tips

Plan ahead

• Read the entire handout first

Test often, fail quickly

• Mistakes are easier to fix earlier than later

• It helps you avoid making the same mistake twice

Optimize repetitive tasks

• Think of procedures to make tasks easier

• Use tools effectively—you only have two hands

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 22

Page 21: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Step 1: Build the arrays

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 23

Bend the anodes and cathodes at different heights,

so they don’t touch. Use pliers, not your fingers.

Page 22: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Step 1: Build the arrays

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 24

Jigs will help you keep the LEDs in place.

Page 23: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Step 1: Build the arrays

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 25

Test that the LEDs light up as you’d expect!

Page 24: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Step 2: Connect the arrays together

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 26

Page 25: Which LED(s) turn on? · Building an LED cube: Key tips Plan ahead •Read the entire handout first Test often, fail quickly •Mistakes are easier to fix earlier than later •It

Step 2: Connect the arrays together

May 5, 2017 ENGR 40M Spring 2017 — C.Z. Lee, J. Plummer, R. Howe 27