From e42058bb82f6d111c284cd129f2253fccd052e14 Mon Sep 17 00:00:00 2001 From: 99cardz Date: Mon, 8 Jan 2024 16:26:56 +0100 Subject: [PATCH] experimenting with xTaskCreate --- src/Dezibot.cpp | 54 +------------------------------------------ src/motion/Motion.cpp | 12 ++++++---- 2 files changed, 9 insertions(+), 57 deletions(-) diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index 3285444..38eb327 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -26,57 +26,5 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define GPIO_LED 48 void Dezibot::begin(void) { - Adafruit_NeoPixel ledStrip = Adafruit_NeoPixel(3, GPIO_LED, NEO_GRB + NEO_KHZ800); - Wire.begin(1, 2); - if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { - Serial.println("SSD1306 allocation failed"); - for (;;); // Don't proceed, loop forever - } - - display.display(); - vTaskDelay(2000); - display.clearDisplay(); - vTaskDelay(2000); - - // Draw a single pixel in white - display.drawPixel(10, 10, SSD1306_WHITE); - - // Show the display buffer on the screen. You MUST call display() after - // drawing commands to make them visible on screen! - display.display(); - vTaskDelay(2000); - - Serial.begin(9600); - Serial.println("start"); - - - vTaskDelay(1000); - - while (1) { - /* Blink off (output low) */ - ledStrip.setPixelColor(1, ledStrip.Color(100, 100, 100)); - ledStrip.show(); // Aktualisiere die Farbe des Pixels - vTaskDelay(1000); - /* Blink on (output high) */ - ledStrip.setPixelColor(1, ledStrip.Color(0, 0, 0)); - ledStrip.show(); // Aktualisiere die Farbe des Pixels - vTaskDelay(1000); - - struct timeval tv_now; - gettimeofday(&tv_now, NULL); - int64_t time_us = (int64_t) tv_now.tv_sec * 1000000L + (int64_t) tv_now.tv_usec; - - - Serial.println(time_us); - - display.clearDisplay(); - - display.setTextSize(2); // Draw 2X-scale text - display.setTextColor(SSD1306_WHITE); - display.setCursor(10, 0); - display.println(F("scroll")); - display.display(); // Show initial text - vTaskDelay(1000); - - } + motion.begin(); } \ No newline at end of file diff --git a/src/motion/Motion.cpp b/src/motion/Motion.cpp index 028aed3..d4c0113 100644 --- a/src/motion/Motion.cpp +++ b/src/motion/Motion.cpp @@ -20,16 +20,20 @@ Motion::Motion() { void Motion::begin(void) { } - -// Move forward for a certain amount of time. -void Motion::move(uint32_t moveForMs) { +void moveTask(void * moveForMs) { analogWrite(MOTOR_LEFT_PIN, 128); analogWrite(MOTOR_RIGHT_PIN, 128); - vTaskDelay(moveForMs); + vTaskDelay((uint32_t) moveForMs); analogWrite(MOTOR_LEFT_PIN, 0); analogWrite(MOTOR_RIGHT_PIN, 0); } +// Move forward for a certain amount of time. +void Motion::move(uint32_t moveForMs) { + xTaskCreate(moveTask, "Move", configMINIMAL_STACK_SIZE, (void*)moveForMs, 1, NULL); +} + + // Rotate clockwise for a certain amount of time. void Motion::rotateClockwise(uint32_t rotateForMs) {