Added ping pong mode (with minor errors).
This commit is contained in:
committed by
s.aydarov
parent
20c25767bd
commit
7861a6d207
@@ -195,13 +195,11 @@ public:
|
||||
}
|
||||
else if(_Run)
|
||||
{
|
||||
uint8_t forward[4] = {P, L, A, NONE};
|
||||
display.setSegments(forward);
|
||||
display.setSegments((const uint8_t[]) {P, L, A, NONE});
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t forward[4] = {P, A, U, S};
|
||||
display.setSegments(forward);
|
||||
display.setSegments((const uint8_t[]) {P, A, U, S});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
{
|
||||
if(_Num < 0)
|
||||
{
|
||||
return (_Max - _Num) % _Max;
|
||||
return (_Max + _Num % _Max);
|
||||
}
|
||||
if(_Num >= _Max)
|
||||
{
|
||||
@@ -133,6 +133,7 @@ private:
|
||||
return (upButtonHold - downButtonHold);
|
||||
}
|
||||
|
||||
//TODO: FIX BUG HERE: display is not updated.
|
||||
void ProcessRun()
|
||||
{
|
||||
ProcessChangeMode();
|
||||
|
||||
28
LEDRunner.h
28
LEDRunner.h
@@ -35,7 +35,10 @@ public:
|
||||
case RunMode::FORWARD: m_CurrentLED = wrapInt(m_CurrentLED + 1, MAX_LED_INDEX + 1); break;
|
||||
case RunMode::BACKWARD: m_CurrentLED = wrapInt(m_CurrentLED - 1, MAX_LED_INDEX + 1); break;
|
||||
//TODO: ADD PING PONG
|
||||
case RunMode::BOTH: m_CurrentLED = wrapInt(m_CurrentLED - 1, MAX_LED_INDEX + 1); break;
|
||||
case RunMode::BOTH:
|
||||
m_CurrentLEDPingPong = wrapInt(m_CurrentLEDPingPong + 1, (MAX_LED_INDEX + 1) * 2);
|
||||
m_CurrentLED = pingPong(m_CurrentLEDPingPong, MAX_LED_INDEX + 1);
|
||||
break;
|
||||
case RunMode::RANDOM: m_CurrentLED = random(0, MAX_LED_INDEX + 1); break;
|
||||
}
|
||||
}
|
||||
@@ -192,13 +195,14 @@ public:
|
||||
bool m_Run = false;
|
||||
unsigned long m_CurrentTime = 0;
|
||||
int m_CurrentLED = 0;
|
||||
int m_CurrentLEDPingPong = 0;
|
||||
ShiftRegister74HC595<REGISTER_SIZE> sr = ShiftRegister74HC595<REGISTER_SIZE>::ShiftRegister74HC595(PIN_LED_DATA, PIN_LED_CLOCK, PIN_LED_LATCH);
|
||||
|
||||
int wrapInt(int _Num, int _Max)
|
||||
{
|
||||
if(_Num < 0)
|
||||
{
|
||||
return (_Max - _Num) % _Max;
|
||||
return (_Max + _Num % _Max);
|
||||
}
|
||||
if(_Num >= _Max)
|
||||
{
|
||||
@@ -208,6 +212,26 @@ public:
|
||||
return _Num;
|
||||
}
|
||||
|
||||
//Fix upper bounce (all LEDs are off)
|
||||
int pingPong(int _Num, int _Max)
|
||||
{
|
||||
if(_Num < 0)
|
||||
{
|
||||
return (_Max + _Num % _Max);
|
||||
}
|
||||
if(_Num > _Max * 2)
|
||||
{
|
||||
return _Num % _Max;
|
||||
}
|
||||
if(_Num > _Max)
|
||||
{
|
||||
return _Max - _Num % _Max;
|
||||
}
|
||||
|
||||
|
||||
return _Num;
|
||||
}
|
||||
|
||||
int wrapInt(int _Num, int _Min, int _Max)
|
||||
{
|
||||
int num = _Num - _Min;
|
||||
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
{
|
||||
if(_Num < 0)
|
||||
{
|
||||
return (_Max - _Num) % _Max;
|
||||
return (_Max + _Num % _Max);
|
||||
}
|
||||
if(_Num >= _Max)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user