[VM110N] Chenillard / light chaser effect

Bonjour, je souhaiterais utiliser ma carte Velleman pour crée un programme de type chenillard en c++, qui correspondrait à ça :

Via un IHM :

  • Choix d’une séquence de chenillard (choix des leds qui s’allume) (bouton)
  • Choix de la vitesse de défilement de celle-ci (bouton validation + edit box avec valeur à mettre en ms)

Physiquement :

  • Appuie sur un bouton, envoie d’une séquence
  • Relâchement du bouton fin de la séquence choisi

Existe t-il une doc, hormis celle des DLL pouvant m’aider à réaliser mon projet ? Merci d’avance !


Hi, i would like to use my card for create a c++ program for an light chaser effect , that looks like this :

With an HMI :

  • Choice sequence chenillard (choice of ON/OFF LED’s with a button)
  • Choice of the chart speed (validation button + edit box with a value in ms)

Physically :
-Press on the button -> Send the sequence
-Release the button -> End the sequence

So, is there a doc, except of those for the DLL of the card, that can help my to realize my project ? Thank’s a lot !

My program for the moment without checkbox for put on/off LEDs :

[code]//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include “Unit1.h”
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource “*.dfm”
TFkitUSBvellman FkitUSBvellman;
//---------------------------------------------------------------------------
__fastcall TFkitUSBvellman::TFkitUSBvellman(TComponent
Owner)
: TForm(Owner)
{
}
void __fastcall TFkitUSBvellman::BconnectClick(TObject *Sender)
{
// Détermination de l’adresse de la carte USB et connexion
char texte[20];
int CardAddr = 3 - (int(CheckBoxSK5->Checked) + int(CheckBoxSK6->Checked) * 2);
unsigned long numCarteConnectee=OpenDevice(CardAddr);
switch (numCarteConnectee)
{
case 0 :
case 1 :
case 2 :
case 3 :
sprintf (texte, " Carte %u connctée" ,CardAddr);
LEtatConnexion->Caption = texte;
LEtatConnexion->Caption = “Carte " + IntToStr(CardAddr) + " connectée”;

	LEtatConnexion->Font->Color = clGreen;
	break;
   case  -1 :
	 LEtatConnexion->Caption = "Carte " + IntToStr(CardAddr) + " introuvable";
	 LEtatConnexion->Font->Color=clRed;
}

}
void __fastcall TFkitUSBvellman::BDeconnectClick(TObject *Sender)
{
CloseDevice(); //fonction “close device” de la dll
LEtatConnexion->Caption = “Carte Déconnectée”;
LEtatConnexion->Font->Color=clPurple;
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::BValidSortiesClick(TObject *Sender)
{
int OutCNA1=(int)ESortieCNA1->Text.ToInt(); //convertir Editox en nbre entier
OutputAnalogChannel(1,OutCNA1); //affecte la valeur outCNA1 à SortieAnalog1
WriteAllDigital(ESortieNum->Text.ToInt()); //affectation des valeurs sorties logiques
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::Timer1Timer(TObject *Sender)
{
long InCAN; //Acquisition mesures CAN
long InNum; // Acquisition entrées numériques
InCAN=ReadAnalogChannel(1); //lire le CAN 1 de carte USB
EEntreeCAN1->Text=InCAN; // affichage valeur InCAN dans EditBox EEntreeCAN1

InCAN=ReadAnalogChannel(2); //lire le CAN2 de carte USB
EEntreeCAN2->Text=InCAN; //affichage valeur InCAN dans EditBox EEntreeCAN2

InNum=ReadAllDigital(); //Lire les entrées numériques
EEntreeNum->Text=InNum; // Afficher l’état des entrées numériques
}
//---------------------------------------------------------------------------[/code]

Note: A Chenillard is usually called a light chaser effect in English. One of those things where lights seem to run along or do other neat tricks like moving back and forth.

I would suggest you download the Software Development Kit from the Velleman site: velleman.eu/support/downloads/?code=K8055

In that you find the source code for demo applications in various languages, including one in VC++ 2008 (I think).

The code in there is relatively simple. Reading from the card is done in a Timer. You would add a second timer object that when active does the light effects. You add code to the timer callback that monitors the inputs to enable/disable that second timer when the button is pressed/released. Rip out everything you don’t need and “voila”.

Regards,
Jan

[quote=“MostlyHarmless”]Note: A Chenillard is usually called a light chaser effect in English. One of those things where lights seem to run along or do other neat tricks like moving back and forth.

I would suggest you download the Software Development Kit from the Velleman site: velleman.eu/support/downloads/?code=K8055

In that you find the source code for demo applications in various languages, including one in VC++ 2008 (I think).

The code in there is relatively simple. Reading from the card is done in a Timer. You would add a second timer object that when active does the light effects. You add code to the timer callback that monitors the inputs to enable/disable that second timer when the button is pressed/released. Rip out everything you don’t need and “voila”.

Regards,
Jan[/quote]

Thank you very much for your reply, and your note haha ! :stuck_out_tongue:

But if i have a close look to the card, i don’t see any links with the buttons and the lights so how can i code a relation between them ?

Note: i use builder c++ for programming

[quote=“Kylvan”]
Thank you very much for your reply, and your note haha ! :stuck_out_tongue: [/quote]

Just helping where I can :slight_smile:

[quote]But if i have a close look to the card, i don’t see any links with the buttons and the lights so how can i code a relation between them ?

Note: i use builder c++ for programming[/quote]

The link between the inputs and the outputs is the PIC (IC3) controlled by “your program”.

Please download and unpack the SDK from the above linked location and go into the K8055DemoVC_2008\K8055Demo directory. There is a precompiled K8055Demo.exe inside the Debug subdirectory, so you don’t need to install Visual Studio to test this out. You need to copy the K8055D.DLL into that Debug directory to run the application.

The demo has a button on the lower left, labeled “Output Test”. This button is actually a CheckBox displayed in button style, so it has a toggle on/off functionality. When you press that, the 8 output LEDs do that light chaser effect, you’re looking for. The relevant code behind all this is found in the file Form1.h.

The callback for that button is the function CheckBox3_CheckedChanged(). When you click on that button, the state toggles and that callback function is called. All it really does is enabling or disabling Timer2.

In Visual Studio, one uses an object System.Windows.Forms.Timer to get a periodic callback. It has two important properties, Interval (ms) and Enabled (true/false). Timer2 in the demo has a 100ms interval. This means that the function Timer2_Tick() is called every 100ms as long as Timer2->Enabled is true.

Take a look at that function. It is really trivial, isn’t it? There is your completely coded example for the light chaser itself already.

For enabling/disabling the chaser with a button on the card itself you are looking for the function Timer1_Tick(). In that function you would check if the input button has changed and set Timer2->Enabled to true/false depending on the state.

[quote=“MostlyHarmless”][quote=“Kylvan”]
Thank you very much for your reply, and your note haha ! :stuck_out_tongue: [/quote]

Just helping where I can :slight_smile:

[quote]But if i have a close look to the card, i don’t see any links with the buttons and the lights so how can i code a relation between them ?

Note: i use builder c++ for programming[/quote]

The link between the inputs and the outputs is the PIC (IC3) controlled by “your program”.

Please download and unpack the SDK from the above linked location and go into the K8055DemoVC_2008\K8055Demo directory. There is a precompiled K8055Demo.exe inside the Debug subdirectory, so you don’t need to install Visual Studio to test this out. You need to copy the K8055D.DLL into that Debug directory to run the application.

The demo has a button on the lower left, labeled “Output Test”. This button is actually a CheckBox displayed in button style, so it has a toggle on/off functionality. When you press that, the 8 output LEDs do that light chaser effect, you’re looking for. The relevant code behind all this is found in the file Form1.h.

The callback for that button is the function CheckBox3_CheckedChanged(). When you click on that button, the state toggles and that callback function is called. All it really does is enabling or disabling Timer2.

In Visual Studio, one uses an object System.Windows.Forms.Timer to get a periodic callback. It has two important properties, Interval (ms) and Enabled (true/false). Timer2 in the demo has a 100ms interval. This means that the function Timer2_Tick() is called every 100ms as long as Timer2->Enabled is true.

Take a look at that function. It is really trivial, isn’t it? There is your completely coded example for the light chaser itself already.

For enabling/disabling the chaser with a button on the card itself you are looking for the function Timer1_Tick(). In that function you would check if the input button has changed and set Timer2->Enabled to true/false depending on the state.[/quote]

Yeah but my project is :

Let the choice to the user to select any sequence, built before by the programmer (me) and then, let him the choice to choose the frequency and the number of sequence and of course a bouton in the HMI to validate the sequences has been choosen. Also use multi threading to avoid the crash of the program and integrate each function of the dll in a class.

At this i’ve created in my HMI one checkbox par LED, and it’s works. Now i’ve to assignate each button to a led but i’ve only 5 button for 8 LEDs so i would like to do something like this :

  • Push bouton1 -> On LED 1 -> Release the button1 -> On LED 2 / OFF LED 1 -> Push/release OFF LED 2

This is the code i’ve done for the checkbox :

[code]void __fastcall TFkitUSBvellman::BReleverClick(TObject *Sender)
{
if (Timer1->Enabled==true)
{
BRelever->Caption=“Débuter mesure”;
Timer1->Enabled=false;
}
else
{
BRelever->Caption=“Arreter mesure”;
Timer1->Enabled=true;
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED1Click(TObject *Sender)
{
if (CheckBoxLED1->Checked)
{
SetDigitalChannel(1);
}
else
{
ClearDigitalChannel(1);
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED2Click(TObject *Sender)
{
if (CheckBoxLED2->Checked)
{
SetDigitalChannel(2);
}
else
{
ClearDigitalChannel(2);
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED3Click(TObject *Sender)
{
if (CheckBoxLED3->Checked)
{
SetDigitalChannel(3);
}
else
{
ClearDigitalChannel(3);
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED4Click(TObject *Sender)
{
if (CheckBoxLED4->Checked)
{
SetDigitalChannel(4);
}
else
{
ClearDigitalChannel(4);
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED5Click(TObject *Sender)
{
if (CheckBoxLED5->Checked)
{
SetDigitalChannel(5);
}
else
{
ClearDigitalChannel(5);
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED6Click(TObject *Sender)
{
if (CheckBoxLED6->Checked)
{
SetDigitalChannel(6);
}
else
{
ClearDigitalChannel(6);
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED7Click(TObject *Sender)
{
if (CheckBoxLED7->Checked)
{
SetDigitalChannel(7);
}
else
{
ClearDigitalChannel(7);
}
}
//---------------------------------------------------------------------------

void __fastcall TFkitUSBvellman::CheckBoxLED8Click(TObject *Sender)
{
if (CheckBoxLED8->Checked)
{
SetDigitalChannel(8);
}
else
{
ClearDigitalChannel(8);
}
}[/code]

My professor say use timer is ugly and there is a windows function to remplace it Oo

Correct me if I’m wrong, but I thought you wanted to build something like this:

jannicash.info/k8055/misc/K8055L … erDemo.zip

I admit that I shamelessly ripped the core of this program from the K8055 SDK Rev 4.0 example for VC_2008. As suggested, I took the existing Demo, added what I needed, threw away what was obsolete. The whole thing took about two hours while cooking dinner on the side.

Your prof is right and wrong.

Timers are not ugly at all. In the above example they are the tool of choice for implementing the visual effect itself. But they are not the perfect tool to implement detecting status changes in the card inputs.

Regards,
Jan

[quote=“MostlyHarmless”]Correct me if I’m wrong, but I thought you wanted to build something like this:

jannicash.info/k8055/misc/K8055L … erDemo.zip

I admit that I shamelessly ripped the core of this program from the K8055 SDK Rev 4.0 example for VC_2008. As suggested, I took the existing Demo, added what I needed, threw away what was obsolete. The whole thing took about two hours while cooking dinner on the side.

Your prof is right and wrong.

Timers are not ugly at all. In the above example they are the tool of choice for implementing the visual effect itself. But they are not the perfect tool to implement detecting status changes in the card inputs.

Regards,
Jan[/quote]

Yeah it’s that i want to make. With an HMI to edit parameters but otherwise it’s that !

But also, the code in the form.h isn’t the same that i actually use.So i try to understund how use it.

The code in Examples\K8055DemoBCB looks like it would be for Borland C++ Builder. You might want to use that as your starting point.

It seems to have very similar functionality, including the timer driven “Output Test”.

The first thing to understand here is that if all you want is an automated sequence of flashing LEDs, like that “Output Test”, you don’t need any of those individual LED CheckBox controls. The thing that does that entire 8 LED loop is the function Timer2Timer(), which is more or less identical to the one found in the VC++ Demo.

[quote=“MostlyHarmless”]The code in Examples\K8055DemoBCB looks like it would be for Borland C++ Builder. You might want to use that as your starting point.

It seems to have very similar functionality, including the timer driven “Output Test”.

The first thing to understand here is that if all you want is an automated sequence of flashing LEDs, like that “Output Test”, you don’t need any of those individual LED CheckBox controls. The thing that does that entire 8 LED loop is the function Timer2Timer(), which is more or less identical to the one found in the VC++ Demo.[/quote]

But i can’t open VC++ files with builder :frowning:

But i can’t open VC++ files with builder :([/quote]

You missed something in my previous post.