I will share my experience about how to turn on and off 8 leds through the widget made using visual basic 6. I am using visual basic 6 because the file is not large and light program execution.
How its work ?
8 pieces led Arduino connected to a digital channel from D2 .. D9. Each LED in series with a resistor about 120Ohm is connected to GND. Thus each led will turn of in a logic 1.
On the Arduino board, was created a program to accept the character as a command to turn off and turn on each LED. Command of the character of 1,2,3,4,5,6,7,8, used to turn on or turn off each LED on arduino board as toggle function. Other characters as command of “*” character serves to turn on all LED. The character “-” to order all led to turn off.
Each character as commands are sent serially to the Arduino board. Thus, the Arduino will send back all conditions of leds in string form., for example, “10101010″. The character “0″ means the condition of the LED is die and vice versa “1″ is alive.
Variable and serial event
As a global variable is “charCmd” defined as byte to hold a character as a command that sent from the PC. Variable of ccmdOk defined as boolean is a flag to mark that character just received from PC. The special variable is stateLED defined as char. This is for holding the state of 8 LEDs in bit for each LED.
The serialEvent() function is event interrupt of microcontroler. This function by default on arduino will call automatically if just completely receive a char from RX pin. If the character has been received from PC, the result will be stored in the variable of “charCmd”, then flag of “cmdOk” is set to “true”.
Two functions are made to treat the LED on the Arduino board are:
Serves to turn on or turn off each LED corresponding to logic of each bit in the variable conditions of stateLED. Line 28, is looping to get each bit of stateLED variable. Every bit of stateLED variable, is tested using bitRead function(). Thus, written to digital channel of arduino. The status of each led is sent to serial and received by PC as hanshaking or display status.
This function serve to invert the logic of each bit on stateLED variable, indexed by n variable. This function have one passing parameter to point each bit on stateLED variable.
This initialization are open serial using 115200baud and making D2 to D9 as output, also all LEDs turn off. For shortened codes, i used loop of for() statement and variable of d is used as index of digital channels that to be connected to LEDs.
The loop functio () checks if there are characters that is sent by the PC. If the variable cmdOk = true, then there are characters received from the PC is stored in the variable of charCmd. Next tested whether the character is ’1′ to ”8′, ‘*’ or ‘-’. If the character are ’1 ‘to ’8′, will call the function of invertLED, means reversing the logic of each bit on variable of stateLED. If the character is ‘*’, stateLED will be assigned to 255 (all LEDs will be turned on), ‘-’ stateLED will be assigned to 0 (all LEDs will be turned off).
Source code of arduino program can be downloaded here.
Widget of visual basic 6
I made this widget by using Visual Basic 6. You can install directly to a computer to download the setup program by clicking here. Or you can download the source program by clicking here. Do not forget to include the name of program creator, and web link on your project.
Last updated byat .