9 enter and run 9 verify that it does the same thing

This preview shows page 184 - 188 out of 354 pages.

9Enter and run DisplayDigitsWithLookup.bs2. 9Verify that it does the same thing as the previous program (with much less work). 9Take a look at the Debug Terminal while the program runs. It shows how the value of indexis used by the LOOKUPcommand to load the correct binary value from the list into OUTH.
Digital Display · Page 185' What's a Microcontroller - DisplayDigitsWithLookup.bs2 ' Use a lookup table to store and display digits with a 7-segment LED display. '{$STAMP BS2} '{$PBASIC 2.5} index VAR Nib OUTH = %00000000 DIRH = %11111111 PAUSE 1000 DEBUG "index OUTH ", CR, "----- --------", CR FOR index = 0 TO 9 LOOKUP index, [ %11100111, %10000100, %11010011, %11010110, %10110100, %01110110, %01110111, %11000100, %11110111, %11110110 ], OUTH DEBUG " ", DEC2 index, " ", BIN8 OUTH, CR PAUSE 1000 NEXT DIRH = %00000000 END Your Turn – Displaying 0 through F Again 9Modify DisplayDigitsWithLookup.bs2 so that it counts from 0 through F in hexadecimal. Don’t forget to update the FOR...NEXTloop’s EndValueargument. ACTIVITY #4: DISPLAYING THE POSITION OF A DIAL In Chapter 5, Activity #4 you used the potentiometer to control the position of a servo. In this activity, you will display the position of the potentiometer using the 7-segment LED display. Dial and Display Parts(1) 7-segment LED display (8) Resistors – 1 k(brown-black-red) (1) Potentiometer – 10 k(1) Resistor – 220 (red-red-brown) (1) Capacitor – 0.1 μF (7) Jumper wires
Page 186· What’s a Microcontroller? Building the Dial and Display CircuitsFigure 6-15 shows a schematic of the potentiometer circuit that should be added to the project. Figure 6-16 shows a wiring diagram of the circuit from Figure 6-15 combined with the circuit from Figure 6-11 on page 176. 9Add the potentiometer circuit to the 7-segment LED display circuit as shown in Figure 6-16. Figure 6-15 Schematic of Potentiometer Circuit Added to the Project Figure 6-16 Wiring Diagram for Figure 6-15 Programming the Dial and DisplayThere is a useful command called LOOKDOWN, and yes, it is the reverse of the LOOKUPcommand. While the LOOKUPcommand gives you a number based on an index, the LOOKDOWNcommand gives you an index based on a number.
Digital Display · Page 187Example Program: SimpleLookdown.bs2 This example program demonstrates how the LOOKDOWNcommand works. 9Enter and run SimpleLookdown.bs2. 9Run the program as-is, with the valuevariable set equal to 167, and use the Debug Terminal to observe the value of index. 9Try setting the valuevariable equal to each of the other numbers listed by the LOOKDOWNcommand: 7, 85, 19, 28. 9Re-run the program after each change to the valuevariable and note which value from the list gets placed in the indexvariable. Trick question: What happens if your value is greater than 167? This little twist in the LOOKDOWNcommand can cause problems because the LOOKDOWNcommand doesn’t make any changes to the index.' What's a Microcontroller - SimpleLookdown.bs2 ' Debug an index using a value and a lookup table.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture