summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore8
-rw-r--r--firmware/lib/buzzer/buzzer.cpp31
-rw-r--r--firmware/lib/buzzer/buzzer.h15
-rw-r--r--firmware/lib/melodies/melodies.cpp60
-rw-r--r--firmware/lib/melodies/melodies.h10
-rw-r--r--firmware/src/main.cpp37
-rw-r--r--include/README (renamed from firmware/include/README)0
-rw-r--r--include/settings.h (renamed from firmware/include/settings.h)19
-rw-r--r--lib/README (renamed from firmware/lib/README)0
-rw-r--r--lib/animations/animations.cpp (renamed from firmware/lib/animations/animations.cpp)0
-rw-r--r--lib/animations/animations.h (renamed from firmware/lib/animations/animations.h)0
-rw-r--r--lib/motors/motors.cpp (renamed from firmware/lib/motors/motors.cpp)60
-rw-r--r--lib/motors/motors.h (renamed from firmware/lib/motors/motors.h)0
-rw-r--r--lib/oled/oled.cpp (renamed from firmware/lib/oled/oled.cpp)0
-rw-r--r--lib/oled/oled.h (renamed from firmware/lib/oled/oled.h)0
-rw-r--r--lib/rgb/rgb.cpp (renamed from firmware/lib/rgb/rgb.cpp)0
-rw-r--r--lib/rgb/rgb.h (renamed from firmware/lib/rgb/rgb.h)0
-rw-r--r--platformio.ini (renamed from firmware/platformio.ini)12
-rw-r--r--src/main.cpp41
19 files changed, 91 insertions, 202 deletions
diff --git a/.gitignore b/.gitignore
index c490ddd..3a37372 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
-firmware/.pio
-firmware/.cache
-firmware/.clangd
-firmware/.ccls
+.pio
+.cache
+.clangd
+.ccls
compile_commands.json
diff --git a/firmware/lib/buzzer/buzzer.cpp b/firmware/lib/buzzer/buzzer.cpp
deleted file mode 100644
index 089f814..0000000
--- a/firmware/lib/buzzer/buzzer.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "buzzer.h"
-#include "settings.h"
-#include <Arduino.h>
-
-#define BUZZER_CHANNEL 3
-#define BUZZER_RESOLUTION 8
-#define BUZZER_FREQ 2000
-
-BUZZER::BUZZER() {}
-
-void BUZZER::init() {
- ledcSetup(BUZZER_CHANNEL, BUZZER_FREQ, BUZZER_RESOLUTION);
- ledcAttachPin(BUZZER_PIN, BUZZER_CHANNEL);
-}
-
-void BUZZER::playTone(uint16_t frequency, uint32_t duration) {
- ledcWriteTone(BUZZER_CHANNEL, frequency);
- if (duration > 0) {
- delay(duration);
- stop();
- }
-}
-
-void BUZZER::playMelody(const uint16_t melody[][2], size_t length) {
- for (size_t i = 0; i < length; i++) {
- playTone(melody[i][0], melody[i][1]);
- delay(50);
- }
-}
-
-void BUZZER::stop() { ledcWriteTone(BUZZER_CHANNEL, 0); }
diff --git a/firmware/lib/buzzer/buzzer.h b/firmware/lib/buzzer/buzzer.h
deleted file mode 100644
index af2ae9d..0000000
--- a/firmware/lib/buzzer/buzzer.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <Arduino.h>
-#include "settings.h"
-
-#pragma once
-
-class BUZZER
-{
-public:
- BUZZER();
-
- void init();
- void playTone(uint16_t frequency, uint32_t duration = 0);
- void stop();
- void playMelody(const uint16_t melody[][2], size_t length);
-};
diff --git a/firmware/lib/melodies/melodies.cpp b/firmware/lib/melodies/melodies.cpp
deleted file mode 100644
index 68e904e..0000000
--- a/firmware/lib/melodies/melodies.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#include <Arduino.h>
-#include "melodies.h"
-
-const uint16_t melody[][2] = {
- {262, 300}, // C4,
- {294, 300}, // D4,
- {330, 300}, // E4,
- {349, 300}, // F4,
- {392, 300}, // G4,
- {440, 300}, // A4,
- {494, 300}, // B4,
- {523, 300} // C5,
-};
-
-
-const uint16_t surprise[][2] = {
- {523, 300}, // C5
- {587, 300}, // D5
- {659, 300}, // E5
- {698, 300}, // F5
- {784, 300}, // G5
- {880, 300}, // A5
- {987, 300}, // B5
- {1047, 300} // C6
-};
-
-const uint16_t alaarm[][2] = {
- {880, 100}, // A5
- {987, 100}, // B5
- {1047, 100}, // C6
- {880, 100}, // A5
- {987, 100}, // B5
- {1047, 100}, // C6
- {880, 100}, // A5
- {987, 100}, // B5
- {1047, 100} // C6
-};
-
-const uint16_t anger[][2] = {
- {440, 100}, // A4
- {523, 100}, // C5
- {587, 100}, // D5
- {659, 100}, // E5
- {698, 100}, // F5
- {784, 100}, // G5
- {880, 100}, // A5
- {987, 100}, // B5
- {1047, 100} // C6
-};
-
-const uint16_t happy[][2] = {
- {262, 300}, // C4
- {294, 300}, // D4
- {330, 300}, // E4
- {349, 300}, // F4
- {392, 300}, // G4
- {440, 300}, // A4
- {494, 300}, // B4
- {523, 300} // C5
-};
diff --git a/firmware/lib/melodies/melodies.h b/firmware/lib/melodies/melodies.h
deleted file mode 100644
index a93877d..0000000
--- a/firmware/lib/melodies/melodies.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <Arduino.h>
-
-#pragma once
-
-const uint16_t happy[][2];
-const uint16_t anger[][2];
-const uint16_t alaarm[][2];
-const uint16_t surprise[][2];
-
-
diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp
deleted file mode 100644
index 880856f..0000000
--- a/firmware/src/main.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "buzzer.h"
-#include "motors.h"
-#include "oled.h"
-#include "rgb.h"
-#include "settings.h"
-#include <Arduino.h>
-
-#include "animations.h"
-
-RGB rgb;
-BUZZER buzzer;
-MOTORS motors; // speed 80 is prefered, because of higher input voltage (5V
- // -> 3.7V after H-bridge), motor is rated for 3V
-// in practice, speed below 70 dosn't even work.
-OLED oled;
-
-void setup() {
- rgb.init();
- buzzer.init();
- motors.init();
- oled.init();
- oled.showMessage("czesc");
- delay(3000);
-}
-
-void loop() {
- oled.showAnimation(animacja1[0], animacja1FrameCount, animacja1Width,
- animacja1Height, 160);
- oled.showAnimation(animacja1[0], animacja1FrameCount, animacja1Width,
- animacja1Height, 80);
- oled.showAnimation(animacja1[0], animacja1FrameCount, animacja1Width + 20,
- animacja1Height, 50); // fajny efekt
- oled.showAnimation(animacja2[0], animacja2FrameCount, animacja2Width,
- animacja2Height, 160);
- oled.showAnimation(animacja2[0], animacja2FrameCount, animacja2Width,
- animacja2Height, 80);
-}
diff --git a/firmware/include/README b/include/README
index 630164d..630164d 100644
--- a/firmware/include/README
+++ b/include/README
diff --git a/firmware/include/settings.h b/include/settings.h
index a06b8c5..b8068c7 100644
--- a/firmware/include/settings.h
+++ b/include/settings.h
@@ -1,35 +1,30 @@
#pragma once
// OLED
-const int OLED_WIDTH = 128;
+const int OLED_WIDTH = 128;
const int OLED_HEIGHT = 64;
-const int OLED_ADDR = 0x3C;
+const int OLED_ADDR = 0x3C;
-const int SCL_PIN = 8;
-const int SDA_PIN = 10;
+const int SCL_PIN = 10;
+const int SDA_PIN = 8;
// RGB LED
-const int RED_PIN = 2;
-const int GREEN_PIN = 4;
-const int BLUE_PIN = 6;
+const int RED_PIN = 9;
+const int GREEN_PIN = 7;
+const int BLUE_PIN = 5;
// MOTORS
const int EN12 = 40;
const int IN1 = 38;
const int IN2 = 36;
-
const int EN34 = 39;
const int IN3 = 37;
const int IN4 = 35;
-
-
-
// const int EN34 = 13;
// const int IN3 = 7;
// const int IN4 = 5;
-
// BUZZER
const int BUZZER_PIN = 13;
diff --git a/firmware/lib/README b/lib/README
index 8d3ee2a..8d3ee2a 100644
--- a/firmware/lib/README
+++ b/lib/README
diff --git a/firmware/lib/animations/animations.cpp b/lib/animations/animations.cpp
index cc5b971..cc5b971 100644
--- a/firmware/lib/animations/animations.cpp
+++ b/lib/animations/animations.cpp
diff --git a/firmware/lib/animations/animations.h b/lib/animations/animations.h
index 628829b..628829b 100644
--- a/firmware/lib/animations/animations.h
+++ b/lib/animations/animations.h
diff --git a/firmware/lib/motors/motors.cpp b/lib/motors/motors.cpp
index ba9f828..843de22 100644
--- a/firmware/lib/motors/motors.cpp
+++ b/lib/motors/motors.cpp
@@ -2,8 +2,8 @@
#include "settings.h"
#include "motors.h"
-#define LEFT_CHANNEL 4
-#define RIGHT_CHANNEL 5
+#define RIGHT_CHANNEL 4
+#define LEFT_CHANNEL 5
#define MOTOR_FREQ 5000
#define MOTOR_RES 10
@@ -19,12 +19,7 @@ MOTORS::MOTORS()
void MOTORS::stop()
{
- ledcWrite(LEFT_CHANNEL, 0);
ledcWrite(RIGHT_CHANNEL, 0);
-}
-
-void MOTORS::leftStop()
-{
ledcWrite(LEFT_CHANNEL, 0);
}
@@ -33,13 +28,18 @@ void MOTORS::rightStop()
ledcWrite(RIGHT_CHANNEL, 0);
}
-void MOTORS::init()
+void MOTORS::leftStop()
{
- ledcSetup(RIGHT_CHANNEL, MOTOR_FREQ, MOTOR_RES);
- ledcAttachPin(EN34, RIGHT_CHANNEL);
+ ledcWrite(LEFT_CHANNEL, 0);
+}
+void MOTORS::init()
+{
ledcSetup(LEFT_CHANNEL, MOTOR_FREQ, MOTOR_RES);
- ledcAttachPin(EN12, LEFT_CHANNEL);
+ ledcAttachPin(EN34, LEFT_CHANNEL);
+
+ ledcSetup(RIGHT_CHANNEL, MOTOR_FREQ, MOTOR_RES);
+ ledcAttachPin(EN12, RIGHT_CHANNEL);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
@@ -47,11 +47,11 @@ void MOTORS::init()
pinMode(IN4, OUTPUT);
}
-void MOTORS::leftForward(int speed, int duration)
+void MOTORS::leftBackward(int speed, int duration)
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
- ledcWrite(LEFT_CHANNEL, scaleSpeed(speed));
+ ledcWrite(RIGHT_CHANNEL, scaleSpeed(speed));
if (duration > 0)
{
@@ -60,11 +60,11 @@ void MOTORS::leftForward(int speed, int duration)
}
}
-void MOTORS::leftBackward(int speed, int duration)
+void MOTORS::leftForward(int speed, int duration)
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
- ledcWrite(LEFT_CHANNEL, scaleSpeed(speed));
+ ledcWrite(RIGHT_CHANNEL, scaleSpeed(speed));
if (duration > 0)
{
@@ -73,12 +73,12 @@ void MOTORS::leftBackward(int speed, int duration)
}
}
-void MOTORS::rightForward(int speed, int duration)
+void MOTORS::rightBackward(int speed, int duration)
{
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
- ledcWrite(RIGHT_CHANNEL, scaleSpeed(speed));
- ledcWrite(LEFT_CHANNEL, 0);
+ ledcWrite(LEFT_CHANNEL, scaleSpeed(speed));
+ ledcWrite(RIGHT_CHANNEL, 0);
if (duration > 0)
{
@@ -87,12 +87,12 @@ void MOTORS::rightForward(int speed, int duration)
}
}
-void MOTORS::rightBackward(int speed, int duration)
+void MOTORS::rightForward(int speed, int duration)
{
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
- ledcWrite(RIGHT_CHANNEL, scaleSpeed(speed));
- ledcWrite(LEFT_CHANNEL, 0);
+ ledcWrite(LEFT_CHANNEL, scaleSpeed(speed));
+ ledcWrite(RIGHT_CHANNEL, 0);
if (duration > 0)
{
@@ -103,8 +103,8 @@ void MOTORS::rightBackward(int speed, int duration)
void MOTORS::forward(int speed, int duration)
{
- rightForward(speed);
leftForward(speed);
+ rightForward(speed);
if (duration > 0)
{
delay(duration);
@@ -114,8 +114,8 @@ void MOTORS::forward(int speed, int duration)
void MOTORS::backward(int speed, int duration)
{
- rightBackward(speed);
leftBackward(speed);
+ rightBackward(speed);
if (duration > 0)
{
delay(duration);
@@ -123,10 +123,10 @@ void MOTORS::backward(int speed, int duration)
}
}
-void MOTORS::rightTurn(int speed, int duration)
+void MOTORS::leftTurn(int speed, int duration)
{
- rightForward(speed);
- leftBackward(speed);
+ leftForward(speed);
+ rightBackward(speed);
if (duration > 0)
{
delay(duration);
@@ -134,13 +134,13 @@ void MOTORS::rightTurn(int speed, int duration)
}
}
-void MOTORS::leftTurn(int speed, int duration)
+void MOTORS::rightTurn(int speed, int duration)
{
- rightBackward(speed);
- leftForward(speed);
+ leftBackward(speed);
+ rightForward(speed);
if (duration > 0)
{
delay(duration);
stop();
}
-} \ No newline at end of file
+}
diff --git a/firmware/lib/motors/motors.h b/lib/motors/motors.h
index b7cc7f1..b7cc7f1 100644
--- a/firmware/lib/motors/motors.h
+++ b/lib/motors/motors.h
diff --git a/firmware/lib/oled/oled.cpp b/lib/oled/oled.cpp
index 2054b8f..2054b8f 100644
--- a/firmware/lib/oled/oled.cpp
+++ b/lib/oled/oled.cpp
diff --git a/firmware/lib/oled/oled.h b/lib/oled/oled.h
index 2d5ff14..2d5ff14 100644
--- a/firmware/lib/oled/oled.h
+++ b/lib/oled/oled.h
diff --git a/firmware/lib/rgb/rgb.cpp b/lib/rgb/rgb.cpp
index 6dc3834..6dc3834 100644
--- a/firmware/lib/rgb/rgb.cpp
+++ b/lib/rgb/rgb.cpp
diff --git a/firmware/lib/rgb/rgb.h b/lib/rgb/rgb.h
index 2c153f1..2c153f1 100644
--- a/firmware/lib/rgb/rgb.h
+++ b/lib/rgb/rgb.h
diff --git a/firmware/platformio.ini b/platformio.ini
index 69b4fc7..a27f556 100644
--- a/firmware/platformio.ini
+++ b/platformio.ini
@@ -8,12 +8,18 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
-[env:adafruit_feather_esp32s2]
+
+[env:lolin_s2_mini]
platform = espressif32
-board = adafruit_feather_esp32s2
+board = lolin_s2_mini
framework = arduino
+monitor_speed = 115200
+
lib_deps =
adafruit/Adafruit GFX Library@^1.12.0
adafruit/Adafruit SSD1306@^2.5.13
-build_flags = -Iinclude \ No newline at end of file
+build_flags =
+ -Iinclude
+ -D ARDUINO_USB_CDC_ON_BOOT=1
+
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..891c11d
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,41 @@
+#include <Arduino.h>
+// #include "esp32-hal.h"
+#include "motors.h"
+#include "rgb.h"
+#include "buzzer.h"
+
+#include "oled.h"
+#include "animations.h"
+
+
+RGB rgb;
+BUZZER buzzer;
+MOTORS motors;
+OLED oled;
+
+
+
+void setup() {
+ motors.init();
+ rgb.init();
+
+ rgb.setColorRGB(0, 0, 0, true);
+
+ oled.init();
+ delay(2000);
+}
+
+void loop() {
+ oled.showAnimation(animacja1[0], animacja1FrameCount, animacja1Width,
+ animacja1Height, 160);
+ oled.showAnimation(animacja1[0], animacja1FrameCount, animacja1Width + 20,
+ animacja1Height, 50); // fajny efekt
+ // oled.showAnimation(animacja2[0], animacja2FrameCount, animacja2Width,
+ // animacja2Height, 160);
+ // oled.showAnimation(animacja2[0], animacja2FrameCount, animacja2Width,
+ // animacja2Height, 80);
+ rgb.rainbowCycle(2000, 7);
+
+ motors.rightForward(100,4000);
+ motors.leftForward(100,4000);
+}