Artem Solomatin
/
pendudu
fsdfds
Diff: main.cpp
- Revision:
- 10:ca38e4d775c8
- Parent:
- 9:e8c6a414e226
- Child:
- 11:6bbe8da4b16a
--- a/main.cpp Thu May 21 15:35:04 2020 +0000 +++ b/main.cpp Fri May 22 12:01:26 2020 +0000 @@ -17,6 +17,8 @@ #define DIR_LEFT 0 #define DIR_RIGHT 1 +//попробовать поменять дир_лефт на -1 + DigitalOut RCout(D10); DigitalOut dir(D9); @@ -284,6 +286,14 @@ } } +int dirCounter = 0; +int perCounter = 0; + +void changeDir(int direction) +{ + dir = direction; +} + void Rx_interrupt() { int command = rpc.getc(); switch (command) { @@ -295,24 +305,34 @@ speedTicker.attach(calcSpeed, 1); break; case 65: - int direction = rpc.getc(); - if (direction <= 0) { - if (dir != DIR_RIGHT) { - dir = DIR_RIGHT; + if (dirCounter == 10) { + dirCounter = 0; + int direction = rpc.getc(); + if (direction <= 0) { + if (dir != DIR_RIGHT) { + changeDir(DIR_RIGHT); + } + } else if (direction > 0) { + if (dir != DIR_LEFT) { + changeDir(DIR_LEFT); + } } - } else if (direction > 0) { - if (dir != DIR_LEFT) { - dir = DIR_LEFT; - } + } else { + dirCounter += 1; } break; case 70: - int newPeriod = rpc.getc(); - if (newPeriod < 26) { - tick.detach(); - } else if (period_us != newPeriod) { - period_us = newPeriod; - periodUpdated = true; + if (perCounter == 40) { + perCounter = 0; + int newPeriod = rpc.getc(); + if (newPeriod < 26) { + tick.detach(); + } else if (period_us != newPeriod) { + period_us = newPeriod; + periodUpdated = true; + } + } else { + perCounter += 1; } break; default: @@ -382,6 +402,6 @@ default: break; } - wait_ms(100); + //wait_ms(100); } } \ No newline at end of file