summaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 3ad9107f1ba0ffea3b2c21f44fc59c8c6ad4ee52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <Arduino.h>
#include "motors.h"
#include "rgb.h"

#include "oled.h"
#include "animations.h"


RGB rgb;
MOTORS motors; 
OLED oled;


TaskHandle_t TaskOled;
TaskHandle_t TaskRgb;
TaskHandle_t TaskMotors;

enum State {
  NEUTRAL,
  HAPPY,
  SAD,
  ANGRY
};

volatile State currentState = NEUTRAL;

void oledTask(void * pvParameters) {
  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;
    }
    vTaskDelay(10 / portTICK_PERIOD_MS); 
  }
}

void rgbTask(void * pvParameters) {
  for(;;) {
    switch(currentState) {
      case HAPPY:
        rgb.setColorRGB(255, 250, 0, 100); 
        rgb.blink(3, 300);
        break;
      case SAD:
        rgb.breathe(3, 40); 
        break;
      case ANGRY:
        rgb.setColorRGB(255, 0, 0, 100); 
        rgb.blink(3, 300);
        break;
      default:
        rgb.setColorRGB(0, 0, 0, true); 
        break;
    }
    vTaskDelay(10 / portTICK_PERIOD_MS);
  }
}


void motorsTask(void * pvParameters) {
  for(;;) {
    switch(currentState) {
      case HAPPY:
        motors.leftTurn(100,1000);
        motors.rightTurn(100,1000);
        break;
      case SAD:
        break;
      case ANGRY:
        motors.forward(100,1000);
        motors.backward(100,1000);
        break;
      default:
        break;
    }
    vTaskDelay(10 / portTICK_PERIOD_MS);
  }
}

void setup() {

  oled.init();
  rgb.init();
  motors.init();
  
  xTaskCreate(oledTask, "OLED Task", 4096, NULL, 1, NULL);
  xTaskCreate(rgbTask, "RGB Task", 2048, NULL, 1, NULL);
  xTaskCreate(motorsTask, "RGB Task", 2048, NULL, 1, NULL);
  
  currentState = NEUTRAL; 
}

void loop() {
  currentState = HAPPY;
  delay(5000);
  currentState = NEUTRAL;
  delay(5000);
  currentState = ANGRY;
  delay(5000);
  currentState = SAD;
  delay(5000);
}