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

From Flowcode Help
Jump to navigationJump to search
Line 9: Line 9:
 
* Open the flowchart 'Headlight warning' which you created in [[Exercise - Dashboard Panel - Adding Objects]].
 
* 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.
 
: This uses one switch, labeled 'main', operating an orange LED on the instrument panel.
 +
 +
 +
==Add the LEDs==
 +
 +
* 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.
 +
  
 
==Add the switches==
 
==Add the switches==
Line 15: Line 23:
 
: In either case, give one coordinates 'X'= 30, 'Y'=5, 'Z'=-2, and the other coordinates 'X'= 60, 'Y'=5, 'Z'=-2.  
 
: 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).
 
: All three switches should have the same size ('Wi...' =2, 'He...'=2, 'De...'=1).
 +
 +
 +
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.
  
 
* Create two further labels, either by dragging them onto the Dashboard panel, using the 'T' icon, or by copying and pasting the 'side' label.  
 
* Create two further labels, either by dragging them onto the Dashboard panel, using the 'T' icon, or by copying and pasting the 'side' label.  
Line 21: Line 33:
 
: All three labels should be the same size, ('Wi...' =10, 'He...'=10, 'De...'=2).
 
: All three labels should be the same size, ('Wi...' =10, 'He...'=10, 'De...'=2).
  
==Add the LEDs==
 
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.
 
  
 +
==Binary arithmetic==
 
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:
 
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
 
Belt (bit 2) Main (bit 1) Side (bit 0) Resulting binary number Equivalent decimal number

Revision as of 16:55, 8 June 2013

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.



Open the 'Headlight warning' flowchart

This uses one switch, labeled 'main', operating an orange LED on the instrument panel.


Add the LEDs

  • 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.


Add the switches

  • 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).


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.
  • 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).


Binary arithmetic

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).