separate led speed is relative to wheel speed

bluepill
JbLb 6 years ago
parent 805e58c072
commit 150b24ff22

@ -278,8 +278,9 @@ void Nunchuk_control()
// ########################## LOOP ########################## // ########################## LOOP ##########################
unsigned long iTimeSend = 0; unsigned long iTimeSendR = 0, iTimeSendL = 0;
int idx_led = 0; int idx_ledR = 0, idx_ledL = 0;
int speedR, speedL;
void loop() void loop()
{ {
@ -289,35 +290,77 @@ void loop()
digitalWrite(LED_BUILTIN, (timeNow % 2000) < 1000); digitalWrite(LED_BUILTIN, (timeNow % 2000) < 1000);
Receive(); Receive();
Nunchuk_control(); Nunchuk_control();
// ********************* simulation *********************************
// in final project need to use Feedback.speedR_meas and Feedback.speedL_meas
//
speedR = cmd2 + cmd1;
speedL = cmd2 - cmd1;
//
// ********************* simulation *********************************
strip.clear(); strip.clear();
strip.setPixelColor(idx_led, strip.Color(128, 0, 0)); strip.setPixelColor(idx_ledR, strip.Color(128, 0, 0));
strip.setPixelColor((NB_STRIP * LED_STRIP) - 1 - idx_led, strip.Color(128, 0, 0)); // second LEDs strip strip.setPixelColor((NB_STRIP * LED_STRIP) - 1 - idx_ledL, strip.Color(128, 0, 0)); // second LEDs strip
strip.show(); strip.show();
if (iTimeSend > timeNow)
return; //*********** 1st led strip ******************
if (cmd2 == 0) if (timeNow > iTimeSendR)
return;
iTimeSend = timeNow + ((200 - abs(cmd2)) * 2); // TIME_SEND
if (cmd2 > 0)
{ {
if (idx_led < LED_STRIP - 1) if (speedR != 0)
{ {
idx_led++; iTimeSendR = timeNow + ((200 - abs(speedR)) * 2); // TIME_SEND
if (speedR > 0)
{
if (idx_ledR < LED_STRIP - 1)
{
idx_ledR++;
} }
else else
{ {
idx_led = 0; idx_ledR = 0;
} }
} }
else else
{ {
if (idx_led > 0) if (idx_ledR > 0)
{ {
idx_led--; idx_ledR--;
} }
else else
{ {
idx_led = LED_STRIP - 1; idx_ledR = LED_STRIP - 1;
}
}
}
}
//*********** 2nd led strip ******************
if (timeNow > iTimeSendL)
{
if (speedL != 0)
{
iTimeSendL = timeNow + ((200 - abs(speedL)) * 2); // TIME_SEND
if (speedL > 0)
{
if (idx_ledL < LED_STRIP - 1)
{
idx_ledL++;
}
else
{
idx_ledL = 0;
}
}
else
{
if (idx_ledL > 0)
{
idx_ledL--;
}
else
{
idx_ledL = LED_STRIP - 1;
}
}
} }
} }
} }

Loading…
Cancel
Save