WAM - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

WAM

Description:

Televisions. VCR's. Disk Drives. Printers. Alarm system control panels ... The LED can be connected to the BS2, which can be programmed to connect and ... – PowerPoint PPT presentation

Number of Views:127
Avg rating:3.0/5.0
Slides: 55
Provided by: robertj3
Category:
Tags: wam | televisions

less

Transcript and Presenter's Notes

Title: WAM


1
WAM
  • Chapter 2
  • Lights On Lights Off

2
The following are some examples of devices that
use indicator lights
  • Car Stereos
  • Televisions
  • VCRs
  • Disk Drives
  • Printers
  • Alarm system control panels

3
Most indicator lights are Light Emitting Diodes
or LEDs
4
The LED can be connected to the BS2, which can be
programmed to connect and disconnect power to it
  • In addition, the BS2 can
  • Turn the LED on and off at different rates
  • Turn an LED on and off a certain number of times
  • Control more than one LED
  • Control a bi-color LED

5
Voltage and Current
  • Voltage and current can be compared to water
    pressure and flow. When the valve is opened,
    what will happen? What determines how fast the
    water will flow?

6
  • Of course water will flow from the fuller tank
    because it has greater pressure than the empty
    tank.
  • The flow rate is dependent on
  • The difference in pressure between the two tanks.
  • The amount of restriction to flow in the pipe and
    valve.
  • The water that flows from your faucet is
    dependent on the height of your town's water
    tank, the size of the pipes, and how far you open
    the faucet.

7
  • In a battery, there is surplus of electrons on
    one side, and a deficiency of electrons on the
    other side (holes).
  • When a circuit is completed, such as putting an
    LED in it, a flow exists from one side to the
    other. This is called Current.

8
  • Current can be viewed in one of 2 ways
  • Electron Flow Electrons flow from the negative
    side(-) to the positive side.OR
  • Conventional Flow The absence of electrons
    move from positive to negative as the electrons
    move.

An atom with an excess of electrons has a
charge. One with a deficiency of electrons has a
charge.
9
  • Which version of flow is used doesn't matter.
    How much flows does. Just as with the water
    tanks
  • The greater the pressure, or the difference in
    potential (Voltage), the greater the amount of
    current that can flow in a unit time (Amperes).
  • The greater the restriction to flow (Ohms), the
    lower the amount current that can flow.

10
Ohm's Law
  • Ohms Law states The amount of current (I) that
    will flow is proportional to the voltage applied
    (V), and inversely proportional to the resistance
    (R) of the circuit. I V/R
  • As Resistance increases, current decreases.

11
  • LEDs have minimal resistance to current flow. A
    5 volt source can destroy an LED if current is
    not restricted. From Ohm's Law, if R is 1 ?, how
    much current will try to flow? An LED drops
    approximately 1.4V, leaving 3.6V.
  • I (5V-1.4V)/1? 3.6 AThe maximum current a
    typical LED can handle is around 30mA, or .030 A.
  • So in this case we would burn out the LED

12
The Resistor
  • The resistor is a device used to limit the amount
    of current in a circuit. Because it is so small,
    color bands are used to identify the value.
  • 1st Band 1st Digit
  • 2nd Band 2nd Digit
  • 3rd Band Multiplier
  • 4th Band (if present) Tolerance.

SchematicSymbol
PartDrawing
13
  • For the resistor shownYellow 4, 1st
    DigitViolet 7, 2nd DigitBrown 1, add 1
    zero.470 Ohm or 470?
  • Tolerance is how far off itcould be from the
    labeledvalueGold 5Silver 10none 20

14
  • Using the 470? resistor in series with the LED,
    how much current will be able to flow with a 5V
    source?(5V-1.4V)/470? 0.0077 Amps or 7.7mA
  • Would this be a safe choice to use in our LED
    circuit?

Answer SureLEDs can allow a maximum of 30ma
15
  • What is the resistance of a resistor colored
    Brown-Black-Orange?

Answer Brown 1, Black 0, Orange 31, 0 ,
3 zeros 10,000 ohms or 10K Ohm
16
LEDs
  • A Diode is like a one-way check valve in that
    current can flow in only one direction. An LED
    is a diode that emits light as current is passed
    through it (Light Emitting Diode).
  • Note the connections on the LED
  • Anode Connected to side ofvoltage. Typically
    has a longer lead.
  • Cathode Connected to side of voltage.
    Typically has a shorter lead AND a flat
    portionon the lens.

17
(No Transcript)
18
(No Transcript)
19
Breadboard Area
  • A Breadboard is an electrical testing area for
    prototyping by quickly connecting components.
  • The rows are electrically connected to make
    connectionsbetween devices.
  • Headers are providedon 2 sides for
  • I/O connections to the BASICStamp (P0-P15)
  • Vdd Voltage (voltage drain drain)
  • Vss - Voltage (voltage source sink)
  • Vin Supply Voltagefrom battery or wall
    transformer

Use of Vin should be used only as directed as it
can damage the BASIC Stamp or components.
20
Activity 1 Building and Testing the LED Circuit
  • Construct the circuit per your text (Pg. 43).
  • As the current path from Vdd() to Vss(-) is
    completed, the LED will light.
  • What happens if the LED is reversed? Try it.
  • What happens if a 1K ohm resistor is used? Try
    it.
  • Why is substituting1kohm safe?
  • Would substituting a 100 ohm resistor be safe? Do
    not try this!!

21
Some useful tips
  • If no light is visible
  • View the LED from above its domed region, LEDS
    emit the most light there
  • Cast a shadow on the LED with your hands
  • If possible, turn the lights off
  • Remember, an LED will only allow a current to
    flow in one direction through it, be sure the
    flat side (-) is closest VSS or ground
  • There must be a difference in potential between
    the two sides of the LED to allow current to flow

22
Activity 2 On/Off Control With the BASIC Stamp
  • With the BASIC Stamp the Input/Output pins
    (P0-P15) are controlled to supply either the Vdd
    () or Vss (-) potential. This will control
    whether a device has a path for current to flow
    or not.

23
(No Transcript)
24
Advantage of BS2 LED control
  • The BS2 can make these changes thousands of times
    per second vs. the human ability of several times
    per minute

25
  • Connect the circuit below.

26
  • Supply power to the boe by switching to 1
  • Enter the code below, save it in
    desktop/wam/chapter2, and run

27
  • The LED should be flashing on and off once per
    second.
  • Key Commands
  • HIGH 14 Places I/O pin P14 High. This
    correlates to 5V or Vdd (digital 1). Current
    flows between P14 and Vss energizing the LED.
    Potential difference exists between two sides of
    LED. Current can flow in correct direction
    through LED.
  • PAUSE 500 BASIC Stamp pauses operation for the
    specified time in milliseconds. 500
    milliseconds 0.5 seconds
  • LOW 14 Places I/O pin P14 Low. This correlates
    to 0V or Vss (digital 0). Current does not flow
    between P14 and Vss, LED is not energized. No
    potential difference between two sides of LED.
  • DO and LOOP Creates a looping structure for
    repetition.

28
  • Now that the LED is blinking per the program,
    test this
  • Disconnect the serial cable from the BASIC Stamp.
    What happens? Why?
  • Turn off power to your BASIC Stamp count to 10
    turn it back on. What happens? Why?

29
  • The program was transmitted to the BASIC Stamp,
    stored in a permanent memory (EEPROM--
    programmable, non-volatile ROM) and the computer
    is no longer required.
  • The BASIC Stamp could now be placed into some
    device to become Embedded Control for the device.
  • A program CANNOT be retrieved from a BASIC Stamp,
    so make sure you save yours!

30
Your turn-Timing repetitions
  • What happens as the arguments for the PAUSE
    instructions are changed?
  • Change both pause durations to 250 ms. This
    should cause the LED to flash on and off every ½
    second right?...TRY IT!
  • Now change the first pause duration to 1000ms and
    the second to 2000 ms..TRY IT!
  • This should have the effect of flashing the led
    on then off every 3 seconds right?
  • See how short you can make the pauses and still
    see the LED flash. TRY IT!
  • To do this start with both durations at 100 and
    reduce each by 5 for every trialonce the light
    looks continuous you will be experiencing what is
    called persistence of vision
  • Last, what would happen if you put an apostrophe
    before the DO and LOOP commands? Why? TRY IT!

31
Activity 3 Counting and Repeating
  • Counting and making decisions based on a value
    are key components to many programs.
  • It is desired to make the LED blink 10 times
    through looping and then stop.

32
Counting with a FOR-NEXT Loop
  • A FOR-NEXT Loop is a simple structure to count
    between 2 values. The NEXT increments the value
    and the loop (NEXT) will repeat if not at the end
    value.

Notice that code inside a loop is indented. This
is a visual aid to assist in seeing blocks of
common code, such as in a loop.
33
Enter, run, and save the code below
' STAMP BS2 ' PBASIC 2.5 'What's a
Microcontroller ledonofftentimes.bs2 'Turn led
on then off. Repeat 10 times. counter VAR
byte FOR counter 1 TO 10 DEBUG ? counter
HIGH 14 PAUSE 500 LOW 14 PAUSE
500 next DEBUG "All done!" end
34
  • Code with full comments

35
Variables
  • Variables are named locations in RAM memory that
    hold data values. The general format for
    defining a variable is Name VAR Type
  • The name you select should be representative of
    what the variable holds and has the following
    limitations
  • Cannot be a word used by PBASIC, such as END or
    LOOP.
  • Cannot contain spaces.
  • May contain numbers or underscores, but cannot
    start with those.
  • Must be less than 33 characters long.
  • By convention, variables start with upper-case
    for each word in it. Examples MyValue,
    ValueIn, Left_Drive

36
  • Variable type defines how large a value a
    variable can hold. The larger the variable, the
    greater the amount of RAM memory used.

37
  • Create a variable to hold the number of pups born
    in a litter.
  • SEE BELOW

Pups_In_Litter VAR NibA Nib was chosen
because a typical maximum is 8, and a Nibble is
the smallest type which could hold this value.
38
  • What happens if the end value in the FOR
    statement is changed from 10 to 20? TRY IT!

39
Should blink 20 times displaying the counter
values 1 through 20 right!
40
What does the STEP command do for a FOR-NEXT
Loop?Replace the FOR statement withFOR Counter
20 TO 120 STEP 10What will be the result?
41
Should only blink 11 times displaying the value
of counter as 20,30,40,50,60,70,80,90,100,110,
120
42
Activity 4 Second LED Circuit.
  • Add a second LED on P15.

43
Enter, Save, and Run TestSecondLed.bs2 as shown
below
' STAMP BS2 ' PBASIC 2.5 'What's a
Microcontroller-TestSecondLed.bs2 'Turn LED
connected to p15 on and off. 'Repeat 1 time per
second indefinitely. DEBUG "Program Running!" Do
HIGH 15 PAUSE 500 LOW 15 PAUSE 500 loop
44
Controlling both LEDs
  • This is done by using two high commands for pins
    14 and 15 before the pause command and two low
    commands after
  • Yes, both LEDs will not turn on and off at
    exactly the same time, but there is no more than
    a millisecond between one high and the next high
    command
  • The human eye cannot detect it! The same is true
    for both lows

45
Enter, Save, and Run FlashBothLeds.bs2 as shown
below
' STAMP BS2 ' PBASIC 2.5 'What's a
Microcontroller-FlshBothLeds.bs2 'Turn LEDs
connected to p14 and p15 on and off. DEBUG
"Program Running!" DO HIGH 14 HIGH 15
PAUSE 500 LOW 14 LOW 15 PAUSE 500 LOOP
46
LEDs can also be programmed to alternate by
swapping the HIGH and LOW commands..Modify the
current program to make this happenModify so you
have the following
  • DEBUG "Program Running!"
  • DO
  • HIGH 15
  • low 15
  • PAUSE 500
  • LOW 14
  • high 15
  • PAUSE 500
  • LOOP

47
Activity 5 Using a Bi-Color LED
  • A Bi-Color LED is one which will light 2
    different colors, such as red or green, depending
    on direction of current flow through it. An
    example is a security light.

48
  • The bi-color LED is simply 2 LED elements in a
    single package connected in opposite ways.

49
  • By using 2 I/O Pins and defining which is Vss
    (LOW) and which is Vdd (HIGH) the direction of
    current flow can be controlled.

Create the circuit as shown above on your BOE
50
Enter, Run, and Save TestBiColorLED.bs2then
check to be sure the colors cycle in the correct
order
' STAMP BS2 ' PBASIC 2.5 'What's a
Microcontroller-TestBicolorLED.bs2 'Turn bi-color
LED red, then green, then off in a loop DEBUG
"program Running!" Do HIGH 15 'red LOW 14
PAUSE 500 LOW 15 'green HIGH 14 PAUSE
500 LOW 15 'off LOW 14 PAUSE 500 Loop
51
Lights Display
  • Now lets use the value of the counter variable to
    control the pause commands duration
  • Rename and save testbicolorled.bs2 as test
    bicolorledyourturn.bs2
  • Add a counter variable declaration before the DO
    statement
  • The resulting code should look like the program
    on the next page

52
Enter, Save, and Run the following code
' STAMP BS2 ' PBASIC 2.5 'What's a
Microcontroller-TestBicolorLEDyourturn.bs2 'This
program should alternate between red and green,
but the time between the change should increase
each timeby 1 ms counter VAR byte do FOR counter
1 TO 50 HIGH 15 LOW 14 PAUSE counter
LOW 15 HIGH 14 PAUSE counter next loop
53
Try changing the loop so that it ends at 100 then
200. Notice the effect. Why does this happen?
54
  • LEDs are just one example of a device that can be
    controlled with simple HIGHs and LOWs from the
    BASIC Stamp.
  • You will find many more in your education and
    experimentations!
Write a Comment
User Comments (0)
About PowerShow.com