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==
 
==Add the LEDs==
 +
[[File:gen_exercisemulticontrol_multisys_01.png|300px|right]]
 
* Add two more 'Single LEDs to the System Panel.  
 
* Add two more 'Single LEDs to the System Panel.  
 
: Do this either from the 'Outputs' toolbox, as you did for the first LED, or by 'copying and pasting' that LED.  
 
: Do this either from the 'Outputs' toolbox, as you did for the first LED, or by 'copying and pasting' that LED.  
: In either case, give one coordinates 'X'= -60, 'Y'=-55, 'Z'=-1.75, and color it green.
+
* In either case,  
: Give the other coordinates 'X'= 60, 'Y'=-55, 'Z'=-1.75, and color it blue.  
+
: give one coordinates 'X'= -60, 'Y'=-55, 'Z'=-1.75, and color it green;
 +
: give the other coordinates 'X'= 60, 'Y'=-55, 'Z'=-1.75, and color it blue.  
 
: All three LEDs should have the same size ('Wi...' =32, 'He...'=32, 'De...'=10).
 
: All three LEDs should have the same size ('Wi...' =32, 'He...'=32, 'De...'=10).
 
  
 
==Connect the LEDs==
 
==Connect the LEDs==
Line 24: Line 26:
 
:: the left-hand LED (green) to PORT A, bit 0,  
 
:: the left-hand LED (green) to PORT A, bit 0,  
 
:: the right-hand (blue) LED to PORT A, bit 2.
 
:: the right-hand (blue) LED to PORT A, bit 2.
 +
 +
  
  
 
==Add the switches==
 
==Add the switches==
 
* Add two more 'Toggle Metal Panel' switches to the Dashboard Panel.  
 
* Add two more 'Toggle Metal Panel' switches to the Dashboard Panel.  
 +
[[File:gen_exercisemulticontrol_multidash_01.png|300px|right]]
 
: As above, you can do this either from the 'Inputs' panel or by 'copying and pasting' the first switch.  
 
: As above, you can do this either from the 'Inputs' panel 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.  
 
: In either case, give one coordinates 'X'= 30, 'Y'=5, 'Z'=-2, and the other coordinates 'X'= 60, 'Y'=5, 'Z'=-2.  
Line 36: Line 41:
 
: Rename the other "belt" and give it coordinates 'X'=60, '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).
 
: All three labels should be the same size, ('Wi...' =10, 'He...'=10, 'De...'=2).
 
  
 
==Connect the switches==
 
==Connect the switches==
Line 77: Line 81:
  
 
The Flowcode program senses this number using the 'switch' icon.
 
The Flowcode program senses this number using the 'switch' icon.
 +
[[File:gen_exercisemulticontrol_multiprog1_01.png|1200px|center]]

Revision as of 09:28, 9 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

  • Add two more 'Single LEDs to the System Panel.
Do this either from the 'Outputs' toolbox, as you did for the first LED, or by 'copying and pasting' that LED.
  • In either case,
give one coordinates 'X'= -60, 'Y'=-55, 'Z'=-1.75, and color it green;
give the other coordinates 'X'= 60, 'Y'=-55, 'Z'=-1.75, and color it blue.
All three LEDs should have the same size ('Wi...' =32, 'He...'=32, 'De...'=10).

Connect the LEDs

The original LED is connected to PORT A, bit 1.

  • Click on the each of the added LEDs in turn, and use the Panel Properties to connect:
the left-hand LED (green) to PORT A, bit 0,
the right-hand (blue) LED to PORT A, bit 2.



Add the switches

  • Add two more 'Toggle Metal Panel' switches to the Dashboard Panel.
Gen exercisemulticontrol multidash 01.png
As above, you can do this either from the 'Inputs' panel 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).

Connect the switches

The original 'main' switch 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.


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
binary
no.
decimal
no.
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 'belt' 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).

When more than one switch is pressed, the number generated, (whether in binary or decimal,)is equal to the sum of these values. So, when the 'belt' switch and the 'side' switch are both pressed, the number produced is '5'.

The Flowcode program senses this number using the 'switch' icon.

Gen exercisemulticontrol multiprog1 01.png