Initial commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32doit-devkit-v1]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32doit-devkit-v1
|
||||||
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
|
lib_deps = stempedia/DabbleESP32@^1.5.1
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
//Pin Configs
|
||||||
|
#define M_DIR_11 15
|
||||||
|
#define M_DIR_12 0
|
||||||
|
#define M_PWM_1 5
|
||||||
|
#define M_DIR_21 4
|
||||||
|
#define M_DIR_22 2
|
||||||
|
#define M_PWM_2 18
|
||||||
|
|
||||||
|
//Motors
|
||||||
|
#define LEFT_MOTOR 1
|
||||||
|
#define RIGHT_MOTOR 2
|
||||||
|
#define BOTH_MOTOR 3
|
||||||
|
|
||||||
|
//Directions
|
||||||
|
#define STOP 0
|
||||||
|
#define FORWARD 1
|
||||||
|
#define BACKWARD 2
|
||||||
|
|
||||||
|
//PWM Configs
|
||||||
|
#define PWM_FREQ 5000
|
||||||
|
#define PWM_RES 8
|
||||||
|
#define PWM_CHANNEL_M1 0
|
||||||
|
#define PWM_CHANNEL_M2 1
|
||||||
+153
@@ -0,0 +1,153 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#define CUSTOM_SETTINGS
|
||||||
|
#define INCLUDE_GAMEPAD_MODULE
|
||||||
|
#include <DabbleESP32.h>
|
||||||
|
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
void setMotorDirection(uint8_t motor ,uint8_t direction = FORWARD);
|
||||||
|
void setMotorSpeed(uint8_t motor, uint8_t speed);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
|
||||||
|
Dabble.begin("Kleiax-Rover"); //set bluetooth name of your device
|
||||||
|
|
||||||
|
//SETUP PINS
|
||||||
|
pinMode(M_DIR_11, OUTPUT);
|
||||||
|
pinMode(M_DIR_12, OUTPUT);
|
||||||
|
pinMode(M_DIR_21, OUTPUT);
|
||||||
|
pinMode(M_DIR_22, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(M_DIR_11, LOW);
|
||||||
|
digitalWrite(M_DIR_12, LOW);
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
|
||||||
|
ledcSetup(PWM_CHANNEL_M1, PWM_FREQ, PWM_RES);
|
||||||
|
ledcSetup(PWM_CHANNEL_M2, PWM_FREQ, PWM_RES);
|
||||||
|
ledcAttachPin(M_PWM_1, PWM_CHANNEL_M1);
|
||||||
|
ledcAttachPin(M_PWM_2, PWM_CHANNEL_M2);
|
||||||
|
ledcWrite(M_PWM_1, 0);
|
||||||
|
ledcWrite(M_PWM_2, 0);
|
||||||
|
|
||||||
|
|
||||||
|
//Start speed
|
||||||
|
setMotorSpeed(BOTH_MOTOR, 255);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
|
||||||
|
//Serial.print("KeyPressed: ");
|
||||||
|
if (GamePad.isUpPressed()) {
|
||||||
|
Serial.print("Up\n");
|
||||||
|
setMotorDirection(BOTH_MOTOR, FORWARD);
|
||||||
|
} else if (GamePad.isDownPressed()) {
|
||||||
|
Serial.print("Down\n");
|
||||||
|
setMotorDirection(BOTH_MOTOR, BACKWARD);
|
||||||
|
} else if (GamePad.isLeftPressed()) {
|
||||||
|
Serial.print("Left\n");
|
||||||
|
setMotorDirection(LEFT_MOTOR, BACKWARD);
|
||||||
|
setMotorDirection(RIGHT_MOTOR, FORWARD);
|
||||||
|
} else if (GamePad.isRightPressed()) {
|
||||||
|
Serial.print("Right\n");
|
||||||
|
setMotorDirection(LEFT_MOTOR, FORWARD);
|
||||||
|
setMotorDirection(RIGHT_MOTOR, BACKWARD);
|
||||||
|
|
||||||
|
} else if (GamePad.isSquarePressed()) {
|
||||||
|
setMotorDirection(LEFT_MOTOR, FORWARD);
|
||||||
|
Serial.print("1\n");
|
||||||
|
} else if (GamePad.isTrianglePressed()) {
|
||||||
|
setMotorDirection(LEFT_MOTOR, BACKWARD);
|
||||||
|
Serial.print("2\n");
|
||||||
|
} else if (GamePad.isCirclePressed()) {
|
||||||
|
setMotorDirection(RIGHT_MOTOR, FORWARD);
|
||||||
|
Serial.print("3\n");
|
||||||
|
} else if (GamePad.isCrossPressed()) {
|
||||||
|
setMotorDirection(RIGHT_MOTOR, BACKWARD);
|
||||||
|
Serial.print("4\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setMotorDirection(BOTH_MOTOR, STOP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMotorDirection(uint8_t motor ,uint8_t direction) {
|
||||||
|
if (motor == LEFT_MOTOR) {
|
||||||
|
if (direction == FORWARD) {
|
||||||
|
digitalWrite(M_DIR_11, HIGH);
|
||||||
|
digitalWrite(M_DIR_12, LOW);
|
||||||
|
} else if (direction == BACKWARD) {
|
||||||
|
digitalWrite(M_DIR_11, LOW);
|
||||||
|
digitalWrite(M_DIR_12, HIGH);
|
||||||
|
} else if (direction == STOP) {
|
||||||
|
digitalWrite(M_DIR_11, LOW);
|
||||||
|
digitalWrite(M_DIR_12, LOW);
|
||||||
|
} else {
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
Serial.print("setDirection: undefined direction\n");
|
||||||
|
}
|
||||||
|
} else if (motor == RIGHT_MOTOR) {
|
||||||
|
if (direction == FORWARD) {
|
||||||
|
digitalWrite(M_DIR_21, HIGH);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
} else if (direction == BACKWARD) {
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, HIGH);
|
||||||
|
} else if (direction == STOP) {
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
} else {
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
Serial.print("setDirection: undefined direction\n");
|
||||||
|
}
|
||||||
|
} else if (motor == BOTH_MOTOR) {
|
||||||
|
if (direction == FORWARD) {
|
||||||
|
digitalWrite(M_DIR_11, HIGH);
|
||||||
|
digitalWrite(M_DIR_12, LOW);
|
||||||
|
digitalWrite(M_DIR_21, HIGH);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
} else if (direction == BACKWARD) {
|
||||||
|
digitalWrite(M_DIR_11, LOW);
|
||||||
|
digitalWrite(M_DIR_12, HIGH);
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, HIGH);
|
||||||
|
} else if (direction == STOP) {
|
||||||
|
digitalWrite(M_DIR_11, LOW);
|
||||||
|
digitalWrite(M_DIR_12, LOW);
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
}else {
|
||||||
|
digitalWrite(M_DIR_11, LOW);
|
||||||
|
digitalWrite(M_DIR_12, LOW);
|
||||||
|
digitalWrite(M_DIR_21, LOW);
|
||||||
|
digitalWrite(M_DIR_22, LOW);
|
||||||
|
Serial.print("setDirection: undefined direction\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.print("setDirection: undefined motor\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMotorSpeed(uint8_t motor, uint8_t speed) {
|
||||||
|
if (motor == LEFT_MOTOR) {
|
||||||
|
ledcWrite(PWM_CHANNEL_M1, speed);
|
||||||
|
} else if (motor == RIGHT_MOTOR) {
|
||||||
|
ledcWrite(PWM_CHANNEL_M2, speed);
|
||||||
|
} else if (motor == BOTH_MOTOR) {
|
||||||
|
ledcWrite(PWM_CHANNEL_M1, speed);
|
||||||
|
ledcWrite(PWM_CHANNEL_M2, speed);
|
||||||
|
} else {
|
||||||
|
ledcWrite(PWM_CHANNEL_M1, 0);
|
||||||
|
ledcWrite(PWM_CHANNEL_M2, 0);
|
||||||
|
Serial.print("setSpeed: undefined motor \n");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user