Hello, I would appreciate if anyone can help me out with this arrray statement. I’m not sure if I have to put it in a function or import a header library so I can use an array. Here is my code, also it is available to anyone who wants to use it. It uses one joystick to drive a a 2 wheel drive bot with the wheels in the centre, like a tank. It also solves the problem of having the joystick go forward and the bot turn and vice versa.
/Alex Wijtowych’s Little addition to the code to make a dual axis drive system with a smoother control!!!/
/Let PWM 09 represent the right wheel of the bot and PWM 10 represent the left wheel of the bot/
int speed_array[255] ={0,0,0,0,0,0,0,4,8,12,16,20,23,27,30,34,37,40,43,45,
48,51,53,56,58,60,63,65,67,69,71,73,75,76,78,80,81,83,84,86,87,88,90,91,
92,93,94,96,97,98,99,100,100,101,102,103,104,105,105,106,107,107,108,
109,109,110,111,111,112,112,113,113,114,114,114,115,115,116,116,116,
117,117,117,118,118,118,119,119,119,119,120,120,120,120,121,121,121,
121,121,122,122,122,122,122,122,123,123,123,123,123,123,123,124,124,
124,124,124,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
127,127,127,127,127,127,127,130,130,130,130,130,131,131,131,131,131,
131,131,132,132,132,132,132,132,133,133,133,133,133,134,134,134,134,
135,135,135,135,136,136,136,137,137,137,138,138,138,139,139,140,140,
140,141,141,142,142,143,143,144,145,145,146,147,147,148,149,149,150,
151,152,153,154,154,155,156,157,158,160,161,162,163,164,166,167,168,
170,171,173,174,176,178,179,181,183,185,187,189,191,194,196,198,201,
203,206,209,211,214,217,220,224,227,231,234,238,242,246,250,254,255,
255,255,255,255,255,255};
if (p1_y > 127 )
{
if (p1_x > 127)
{
pwm09 = speed_array[255 - (2 *(p1_x - 127))];
pwm10 = speed_array[p1_y];
}
else if (p1_x < 127)
{
pwm09 = speed_array[255 - p1_y];
pwm10 = speed_array[255 - (2 *(127 - p1_x))];
}
else if (p1_x == 127)
{
pwm09 = speed_array[p1_y - 127];
pwm10 = speed_array[p1_y];
}
}
else if (p1_y < 127)
{
if (p1_x > 127)
{
pwm09 = speed_array[255 - (2 *(p1_x - 127))];
pwm10 = speed_array[p1_y];
}
else if (p1_x < 127)
{
pwm09 = speed_array[255 - p1_y];
pwm10 = speed_array[2 *(127 - p1_x)];
}
else if (p1_x == 127)
{
pwm09 = speed_array[127 + (127 - p1_y)];
pwm10 = speed_array[p1_y];
}
}
else if (p1_y == 127)
{
if (p1_x < 127)
{
pwm09 = speed_array[127 + (127 - p1_x)];
pwm10 = speed_array[p1_x];
}
else if (p1_x > 127)
{
pwm09 = speed_array[127 - (p1_x - 127)];
pwm10 = speed_array[p1_x];
}
else if (p1_x == 127)
{
pwm09 = 127;
pwm10 = 127;
}
}