From 26647017c3e65b3fb85ffee6c205233cb2254d21 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Sun, 31 Jul 2022 17:50:03 +0930 Subject: [PATCH] Initialise arrays on the stack in esp32 servo --- esp32/src/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index e189f14..60e892d 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -33,27 +33,25 @@ void setupServos(uint8_t size, uint8_t *calibrationValues) void modifyServo(uint8_t channel, uint8_t newAngle) { - if(servos.count(channel) > 0){ + if (servos.count(channel) > 0) + { servos[channel]->write(newAngle); - } + } } void loop() { - uint8_t *header = new uint8_t[2]; + uint8_t header[2]; Serial.readBytes(header, 2); if (header[0] == 0) { - uint8_t *calibration = new uint8_t[2 * header[1]]; + uint8_t calibration[2 * header[1]]; Serial.readBytes(calibration, header[1]); setupServos(header[1], calibration); - delete [] calibration; } else { modifyServo(header[0], header[1]); } - - delete [] header; } \ No newline at end of file