Difference between revisions of "Exercise - Dashboard and System Panel - Controlling Multiple Objects"

From Flowcode Help
Jump to navigationJump to search
(Replaced content with "For an excellent introduction guide, we recommend [https://www.flowcode.co.uk/education/ Introduction to microcontroller programming]")
Tag: Replaced
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This exercise shows how to add two more LEDs to the car's instrument panel, each controlled separately by switches on the Dashboard Panel. These will warn the driver that the sidelights are switched on, and that a seatbelt is not fastened.
+
For an excellent introduction guide, we recommend [https://www.flowcode.co.uk/education/ Introduction to microcontroller programming]
 
 
 
 
__TOC__
 
 
 
 
 
==Open the 'Headlight warning' flowchart==
 
 
 
* Open the flowchart 'Headlight warning' which you created in [[Exercise - Dashboard Panel - Adding Objects]].
 
: This uses one switch, labeled 'main', operating an orange LED on the instrument panel.
 
 
 
* Add two more 'Toggle Metal Panel' switches to the Dashboard Panel.
 
: Do this either from the 'Inputs' panel, as you did for the first, or by 'copying and pasting' the first switch.
 
: In either case, give one coordinates 'X'= 30, 'Y'=5, 'Z'=-2, and the other coordinates 'X'= 60, 'Y'=5, 'Z'=-2.
 
: All three switches should have the same size ('Wi...' =2, 'He...'=2, 'De...'=1).
 
 
 
* Create two further labels, either by dragging them onto the Dashboard panel, using the 'T' icon, or by copying and pasting the 'side' label.
 
: In either case, rename one "side", and give it coordinates 'X'=30, 'Y'=-15, 'Z'=0.5.
 
: Rename the other "belt" and give it coordinates 'X'=60, 'Y'=-15, 'Z'=0.5.
 
: All three labels should be the same size, ('Wi...' =10, 'He...'=10, 'De...'=2).
 
 
 
The switch above the 'main' label is attached to PORT B, bit 0.
 
* Connect the switch above the 'side' label to PORT B, bit 1, and the one above the 'belt'label to PORTB,2.
 
 
 
* On the instrument panel, connect the left-hand LED to PORT A, bit 0 and color it yellow.
 
* Connect the middle LED to PORT A, bit 1, and color it red.
 
* Connect the right-hand LED to PORT A, bit 2, and color it green.
 
 
 
Before creating the Flowcode program, here is a little background in binary arithmetic. The switches don't have to be read as separate items. Instead, they can  be used to control the first three bits of a binary number applied to PORT B. The table shows the input binary number resulting from different combinations of switch presses:
 
Belt (bit 2) Main (bit 1) Side (bit 0) Resulting binary number Equivalent decimal number
 
0 0 0 000 0
 
0 0 1 001 1
 
0 1 0 010 2
 
0 1 1 011 3
 
1 0 0 100 4
 
1 0 1 101 5
 
1 1 0 110 6
 
1 1 1 111 7
 
 
 
The way this works:
 
The 'fog' switch is worth '4' in decimal, because it controls the third binary digit, and so is worth 22 (=4).
 
The 'main' switch is worth '2' in decimal, because it controls the second binary digit, and so is worth 21 (=2).
 
The 'side' switch is worth '1' in decimal, because it controls the first binary digit, and so is worth 20 (=1).
 

Latest revision as of 13:37, 25 April 2023

For an excellent introduction guide, we recommend Introduction to microcontroller programming