summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorEnricoGuccii <partyka.003@proton.me>2026-05-30 22:37:18 +0200
committerEnricoGuccii <partyka.003@proton.me>2026-05-30 22:37:18 +0200
commit4e7ededde5bbaa5cb9d882f1fe100d48784b94be (patch)
tree137f2aa4faa4f00cadf66446df1d4ae6686182c7 /src/main.cpp
parent6341278d67ec8875b869c4d101b59385db819258 (diff)
switch to FluxGarage/RoboEyesmain
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp162
1 files changed, 107 insertions, 55 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 3ad9107..91b5394 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,86 +1,134 @@
#include <Arduino.h>
+#include <Wire.h>
+
+#include <Adafruit_GFX.h>
+#include <Adafruit_SSD1306.h>
+#include <FluxGarage_RoboEyes.h>
+
+#include "settings.h"
#include "motors.h"
#include "rgb.h"
-#include "oled.h"
-#include "animations.h"
+Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &Wire, -1);
+RoboEyes<Adafruit_SSD1306> roboEyes(display);
RGB rgb;
MOTORS motors;
-OLED oled;
-
TaskHandle_t TaskOled;
TaskHandle_t TaskRgb;
TaskHandle_t TaskMotors;
-enum State {
- NEUTRAL,
- HAPPY,
- SAD,
- ANGRY
+enum RobotEmotion {
+ E_NEUTRAL,
+ E_HAPPY,
+ E_SAD,
+ E_ANGRY
};
-volatile State currentState = NEUTRAL;
+volatile RobotEmotion currentState = E_NEUTRAL;
+
+
+void oledSetup(){
+ Wire.begin(SDA_PIN, SCL_PIN);
+ delay(250);
+ display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
+ roboEyes.begin(OLED_WIDTH, OLED_HEIGHT, 50);
+ roboEyes.setAutoblinker(ON, 3, 2);
+ roboEyes.setIdleMode(ON, 2, 2);
+}
void oledTask(void * pvParameters) {
+ RobotEmotion lastEmotion = E_NEUTRAL;
+
for(;;) {
- switch(currentState) {
- case HAPPY:
- oled.showAnimation(animacja1[0], animacja1FrameCount, animacja1Height, animacja1Width, 160);
- break;
- case SAD:
- oled.showAnimation(animacja2[0], animacja2FrameCount, animacja2Height, animacja2Width, 160);
- break;
- case ANGRY:
- oled.showMessage("angry");
- break;
- default:
- oled.showMessage("neutral");
- break;
+ if (currentState != lastEmotion) {
+ lastEmotion = currentState;
+
+ switch(currentState) {
+ case E_HAPPY:
+ roboEyes.setMood(HAPPY);
+ break;
+ case E_SAD:
+ roboEyes.setMood(TIRED);
+ break;
+ case E_ANGRY:
+ roboEyes.setMood(ANGRY);
+ break;
+ default:
+ roboEyes.setMood(DEFAULT);
+ break;
+ }
}
- vTaskDelay(10 / portTICK_PERIOD_MS);
+
+ roboEyes.update();
+
+ vTaskDelay(20 / portTICK_PERIOD_MS);
}
}
void rgbTask(void * pvParameters) {
+ RobotEmotion lastEmotion = E_NEUTRAL;
+
+ rgb.setColorRGB(0, 0, 0, true);
+
for(;;) {
+ if (currentState != lastEmotion) {
+
+ switch(currentState) {
+ case E_HAPPY:
+ rgb.fadeColor(255, 250, 0, 500);
+ break;
+ case E_SAD:
+ rgb.fadeColor(118, 116, 237, 500);
+ break;
+ case E_ANGRY:
+ rgb.fadeColor(255, 0, 0, 500);
+ break;
+ case E_NEUTRAL:
+ default:
+ rgb.fadeColor(0, 0, 0, 500);
+ break;
+ }
+ lastEmotion = currentState;
+ }
+
switch(currentState) {
- case HAPPY:
- rgb.setColorRGB(255, 250, 0, 100);
- rgb.blink(3, 300);
+ case E_HAPPY:
+ rgb.blink(1, 300);
break;
- case SAD:
- rgb.breathe(3, 40);
+ case E_SAD:
+ rgb.breathe(1, 40);
break;
- case ANGRY:
- rgb.setColorRGB(255, 0, 0, 100);
- rgb.blink(3, 300);
+ case E_ANGRY:
+ rgb.blink(1, 300);
break;
+ case E_NEUTRAL:
default:
- rgb.setColorRGB(0, 0, 0, true);
break;
}
- vTaskDelay(10 / portTICK_PERIOD_MS);
+
+ vTaskDelay(20 / portTICK_PERIOD_MS);
}
}
-
void motorsTask(void * pvParameters) {
for(;;) {
switch(currentState) {
- case HAPPY:
- motors.leftTurn(100,1000);
- motors.rightTurn(100,1000);
+ case E_HAPPY:
+ motors.leftTurn(100, 1000);
+ motors.rightTurn(100, 1000);
break;
- case SAD:
+ case E_SAD:
+ motors.stop();
break;
- case ANGRY:
- motors.forward(100,1000);
- motors.backward(100,1000);
+ case E_ANGRY:
+ motors.forward(100, 1000);
+ motors.backward(100, 1000);
break;
default:
+ motors.stop();
break;
}
vTaskDelay(10 / portTICK_PERIOD_MS);
@@ -89,24 +137,28 @@ void motorsTask(void * pvParameters) {
void setup() {
- oled.init();
rgb.init();
motors.init();
+ oledSetup();
- xTaskCreate(oledTask, "OLED Task", 4096, NULL, 1, NULL);
- xTaskCreate(rgbTask, "RGB Task", 2048, NULL, 1, NULL);
- xTaskCreate(motorsTask, "RGB Task", 2048, NULL, 1, NULL);
+ xTaskCreate(oledTask, "OLED Task", 4096, NULL, 1, &TaskOled);
+ xTaskCreate(rgbTask, "RGB Task", 2048, NULL, 1, &TaskRgb);
+ xTaskCreate(motorsTask, "Motors Task", 2048, NULL, 1, &TaskMotors);
- currentState = NEUTRAL;
+ currentState = E_NEUTRAL;
+ vTaskDelay(5000 / portTICK_PERIOD_MS);
}
void loop() {
- currentState = HAPPY;
- delay(5000);
- currentState = NEUTRAL;
- delay(5000);
- currentState = ANGRY;
- delay(5000);
- currentState = SAD;
- delay(5000);
+ currentState = E_HAPPY;
+ vTaskDelay(5000 / portTICK_PERIOD_MS);
+
+ currentState = E_NEUTRAL;
+ vTaskDelay(5000 / portTICK_PERIOD_MS);
+
+ currentState = E_ANGRY;
+ vTaskDelay(5000 / portTICK_PERIOD_MS);
+
+ currentState = E_SAD;
+ vTaskDelay(5000 / portTICK_PERIOD_MS);
}