17
A Breathing LED Indicator EAS 199A Notes Gerald Recktenwald Portland State University Department of Mechanical Engineering [email protected] EAS 199A: Breathing LED equations

A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

A Breathing LED IndicatorEAS 199A Notes

Gerald Recktenwald

Portland State University

Department of Mechanical Engineering

[email protected]

EAS 199A: Breathing LED equations

Page 2: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Motivation

1. A reverse engineering exercise: emulate the breathing style of LED pulsing on a

Macintosh laptop

2. Controlling LED brightness requires Pulse-width modulation (PWM), which can also

used to control the speed of DC motors.

3. This is also an opportunity to practice algebra and Excel plotting

EAS 199A: Breathing LED equations page 1

Page 3: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

US Patent # 6,658,577 B2

EAS 199A: Breathing LED equations page 2

Page 4: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

US Patent # 6,658,577 B2

EAS 199A: Breathing LED equations page 3

Page 5: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

The breathing pattern has three phases: inhale, pause, and exhale

t0

Vmin

Vmax

t1 t2 t3

Inhale Pause Exhale

Note: This not the pattern claimed on US patent # 6658577.

EAS 199A: Breathing LED equations page 4

Page 6: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

The breathing pattern repeats indefinitely

t0

Vmin

Vmax

t1 t2 t3

Inhale Pause Exhale

(t1+t3) (t2+t3) 2t3

Inhale Pause Exhale Inhale

...

...

EAS 199A: Breathing LED equations page 5

Page 7: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

The repeated pattern is the body of the loop function

t0

Vmin

Vmax

t1 t2 t3

void loop() {

// -- Inhale code

// -- Pause code

// -- Exhale code

}

Inhale Pause Exhale

EAS 199A: Breathing LED equations page 6

Page 8: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Inhale and exhale Functions have the same form

Inhale and exhale functions are of the form

v = aebt

(1)

Require that this function pass through two

points (tA, vA) and (tB, vB). t0

Vmin

Vmax

A

B

t1 t2 t3

Substituting these data pairs into Equation (1) gives

vA = aebtA (2)

vB = aebtB (3)

EAS 199A: Breathing LED equations page 7

Page 9: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Linearize the Equations to Simply the Algebra

Recall that if

z = xy

then

ln(z) = ln(x) + ln(y).

In words: the logarithm of a product is the sum of the logarithms of the terms being

multiplied.

Also recall that if

r = est

then

ln(r) = st.

EAS 199A: Breathing LED equations page 8

Page 10: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Linearize the Equations to Simply the Algebra

Take the logarithm of Equation (1) and apply the rules for manipulating logarithms of

products:

ln(v) = ln[ae

bt]−→ ln(v) = ln(a) + ln

[ebt]−→ ln(v) = ln(a) + bt

Apply the transformation to Equations (2) and (3) to get

ln(vA) = ln(a) + btA (4)

ln(vB) = ln(a) + btB (5)

These are two linear equations for the two unknowns, ln(a) and b. The linear equations

can be solved more easily.

EAS 199A: Breathing LED equations page 9

Page 11: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Solve for a and b (1)

Subtract Equation (5) from Equation (4) to get

ln(vA)− ln(vB) = b(tA − tB) (6)

Since tA, vA, tB and vB are known, we can solve for b

b =ln(vA)− ln(vB)

tA − tB. (7)

EAS 199A: Breathing LED equations page 10

Page 12: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Solve for a and b (2)

Now that the formula for b is known, we can substitute Equation (7) into either

Equation (4) or Equation (5) to solve for a.

ln(vA) = ln(a) +

[ln(vA)− ln(vB)

tA − tB

]tA

ln(a) = ln(vA)−[ln(vA)− ln(vB)

tA − tB

]tA

= ln(vA)

[tA − tB

tA − tB

]−[ln(vA)− ln(vB)

tA − tB

]tA

=ln(vA) [tA − tB]− [ln(vA)− ln(vB)] tA

tA − tB

=tA ln(vB)− tB ln(vA)

tA − tB

EAS 199A: Breathing LED equations page 11

Page 13: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Solve for a and b (3)

Therefore,

ln(a) =tA ln(vB)− tB ln(vA)

tA − tB

Applying the exponential function to both sides of the preceding equation gives the

formula for computing a

a = exp

[tA ln(vB)− tB ln(vA)

tA − tB

](8)

EAS 199A: Breathing LED equations page 12

Page 14: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

We have created the formulas that model either inhale or exhale

Given (tA, vA) and (tB, vB), we can compute

a = exp

[tA ln(vB)− tB ln(vA)

tA − tB

]and

b =ln(vA)− ln(vB)

tA − tB.

which allows us to evaluate

v = aebt

for any t in the interval tA ≤ t ≤ tB.

t0

Vmin

Vmax

A

B

t1 t2 t3

EAS 199A: Breathing LED equations page 13

Page 15: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Applying the Equations to find a and b (1)

1. Choose appropriate values of Vmin, Vmax, t1, t2 and t3. These are somewhat arbitrary

design choices that you make to achieve a desired look to your inhale and exhale

functions.

2. Use Equations (8) and (7) to compute ain and bin.

3. Use Equations (8) and (7) (again) to compute aex and bex.

EAS 199A: Breathing LED equations page 14

Page 16: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Applying the Equations to find a and b (2)

Once you have obtained values for ain, bin, aex and bex, it is a good idea to add this step

4. Plot the vin(t) and vex(t) functions (say, with Excel or Matlab) to make sure you

do not have an error in your algebra.

EAS 199A: Breathing LED equations page 15

Page 17: A Breathing LED Indicator - Computer Action Teamweb.cecs.pdx.edu/~gerry/class/EAS199A/notes/07/breathing... · 2011-10-17 · The breathing pattern has three phases: inhale, pause,

Recapitulation

So far:

1. Both the inhale and exhale phases can be modeled with v = aebt

2. We choose the end points to give a desired shape.

3. When the endpoints are known, we can solve for a and b.

4. With known values of a and b for each phase, we can write code to control the

brightness of the LED.

Next: translate the v = aebt function into Arduino code.

But first: Let’s make a plot of our v = aebt functions to make sure we understand the

math.

EAS 199A: Breathing LED equations page 16