In this project we’ll build a tool to control lighting and speed of a DC motor.
Tools:1. Hexabitz Thumb Joystick Module (H10R4x).
2. Hexabitz MOSFET Switch Module (H0FR7).
3. Hexabitz RGB LED Module (H01R0x).
4. Hexabitz STLINK-V3MODS Programmer Module (H40Rx).
5. Hexabitz FTDI USB to UART Serial cable.
6. Hexabitz Bitz Clamp.
7. DC Motor.
The first step:
Connect the modules as shown in the following figure.
One of the most amazing features of Hexabitz modules is the ability of choosing whatever shape you wish to assemble, for an instance shaping them as below is not by force, you have the freedom to choose any shape you want before soldering.
The second step:
Now, let's walk through the code together.
1. Define the variables used in the code.
The first variable (axis_selection) to select the action axis (X or Y).
The second variable (max_value) to set the maximum value for speed or lighting.
The third variable (u) is the control beam that controls the desired speed or the lighting.
The fourth variable (select) is to select the installation mode or not to install (speed or lighting).
Speed limit select = 1 , No speed limit select = 0
bool axis_selection=0;
int max_value=100;
int u=0;
int select = 0;
void UserTask(void * argument)
{
for(;;)
{
Get_variant_value(&axis_selection,&max_value, &u, select);
if(u>0)
{ messageParams[0] = 0;
messageParams[1] = CYAN;
messageParams[2] = u;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
Delay_ms(1);
messageParams[0] = u;
SendMessageToModule(3, CODE_H0FR6_PWM, 1);
}
else
{ SendMessageToModule(2, CODE_H01R0_OFF, 0);
Delay_ms(1);
SendMessageToModule(3, CODE_H0FR6_OFF, 0);}
}
}
If we wish to set the value of velocity to a certain value, you should set select = 1.
bool axis_selection=0;
int max_value=100;
int s=0;
int select = 1;
void UserTask(void * argument)
{
for(;;)
{
Get_variant_value(&axis_selection,&max_value, &u, select);
if(s>0)
{ messageParams[0] = 0;
messageParams[1] = CYAN;
messageParams[2] = s;
SendMessageToModule(2, CODE_H01R0_COLOR, 3);
Delay_ms(1);
messageParams[0] = s;
SendMessageToModule(3, CODE_H0FR6_PWM, 1);
}
else
{ SendMessageToModule(2, CODE_H01R0_OFF, 0);
Delay_ms(1);
SendMessageToModule(3, CODE_H0FR6_OFF, 0);}
}
}
I hope you enjoyed reading this article. Follow me if you would like to see more projects in the future. Feel free to write any comments, I will always be happy to help.
- Video link:
Good Luck.
- Hexabitz Company Website
Comments