Velleman nv – Velleman projects EDU05 Assembly instructions User Manual
Page 15

EDU05 Test procedure & programming in Visual Basic 2010 ( Version 1.0)
15
To read the status of the buttons you can use the function
ReadAllDigital().
This function returns a 32 bit integer.
The eight lowest bits of this return value represent the status of the eight buttons. If you press a button, the
corresponding bit is set to "1".
You can use Visual Basic's
And
operator to mask the other bits and check the value of an individual bit.
Example: If buttons SW1, SW2 and SW8 are pressed, the eight last bits of the value are 10000011.
In this code example the button status value is read to integer i.
Every bit is checked if it is "1" or "0". If the bit is "1", it means the corresponding switch is pressed. The text
"DOWN" is displayed for this button
.
Dim
i
As
Integer
i = ReadAllDigital()
' check the individual bits of i to detect the pressed buttons
If
(i
And
1) > 0
Then
Label3.Text =
"SW1 = Pressed"
Else
Label3.Text =
"SW1 = Released"
If
(i
And
2) > 0
Then
Label4.Text =
"SW2 = Pressed"
Else
Label4.Text =
"SW2 = Released"
If
(i
And
4) > 0
Then
Label5.Text =
"SW3 = Pressed"
Else
Label5.Text =
"SW3 = Released"
If
(i
And
8) > 0
Then
Label6.Text =
"SW4 = Pressed"
Else
Label6.Text =
"SW4 = Released"
If
(i
And
16) > 0
Then
Label7.Text =
"SW5 = Pressed"
Else
Label7.Text =
"SW5 = Released"
If
(i
And
32) > 0
Then
Label8.Text =
"SW6 = Pressed"
Else
Label8.Text =
"SW6 = Released"
If
(i
And
64) > 0
Then
Label9.Text =
"SW7 = Pressed"
Else
Label9.Text =
"SW7 = Released"
If
(i
And
128) > 0
Then
Label10.Text =
"SW8 = Pressed"
Else
Label10.Text =
"SW8 = Released"
STEP11
When you are finished evaluating this project, you can close it. Next, open the project Set_LED to study how to turn
LEDs on and off on the EDU05 board.
Velleman NV
Legen Heirweg 33
9890 Gavere, Belgium
www.velleman.eu