hh
This commit is contained in:
97
firmwareCarroEsp32/src/OpenTB6612FNG/OpenTB6612FNG.cpp
Normal file
97
firmwareCarroEsp32/src/OpenTB6612FNG/OpenTB6612FNG.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
# include "Arduino.h"
|
||||
# include "OpenTB6612FNG.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
OpenTB6612FNG::OpenTB6612FNG(int TP) {
|
||||
|
||||
pinMode(PWMA, OUTPUT);
|
||||
pinMode(AIN1, OUTPUT);
|
||||
pinMode(AIN2, OUTPUT);
|
||||
pinMode(STBY, OUTPUT);
|
||||
pinMode(BIN1, OUTPUT);
|
||||
pinMode(BIN2, OUTPUT);
|
||||
pinMode(PWMB, OUTPUT);
|
||||
ledcSetup(ledChannel, freq, resolution);
|
||||
ledcSetup(ledChannel2, freq, resolution);
|
||||
|
||||
// attach the channel to the GPIO to be controlled
|
||||
ledcAttachPin(PWMA, ledChannel);
|
||||
ledcAttachPin(PWMB, ledChannel2);
|
||||
|
||||
}
|
||||
|
||||
void OpenTB6612FNG::MotorIz(int value) {
|
||||
/* if (value >= 0) {
|
||||
// si valor positivo vamos hacia adelante
|
||||
|
||||
digitalWrite(AIN1, HIGH);
|
||||
digitalWrite(AIN2, LOW);
|
||||
} else {
|
||||
// si valor negativo vamos hacia atras
|
||||
|
||||
digitalWrite(AIN1, LOW);
|
||||
digitalWrite(AIN2, HIGH);
|
||||
value *= -1;
|
||||
}
|
||||
*/
|
||||
// Setea Velocidad
|
||||
|
||||
ledcWrite(ledChannel, value);
|
||||
}
|
||||
|
||||
void OpenTB6612FNG::MotorDe(int value) {
|
||||
/* if (value >= 0) {
|
||||
// si valor positivo vamos hacia adelante
|
||||
|
||||
digitalWrite(BIN1, HIGH);
|
||||
digitalWrite(BIN2, LOW);
|
||||
} else {
|
||||
// si valor negativo vamos hacia atras
|
||||
|
||||
digitalWrite(BIN1, LOW);
|
||||
digitalWrite(BIN2, HIGH);
|
||||
value *= -1;
|
||||
}
|
||||
*/
|
||||
// Setea Velocidad
|
||||
|
||||
ledcWrite(ledChannel2, value);
|
||||
}
|
||||
|
||||
void OpenTB6612FNG::Motores(int left, int righ) {
|
||||
MotorIz(left);
|
||||
MotorDe(righ);
|
||||
digitalWrite(STBY, LOW);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OpenTB6612FNG::Forward()
|
||||
{
|
||||
digitalWrite(AIN1, HIGH);
|
||||
digitalWrite(AIN2, LOW);
|
||||
digitalWrite(BIN1, HIGH);
|
||||
digitalWrite(BIN2, LOW);
|
||||
}
|
||||
|
||||
void OpenTB6612FNG::Backward()
|
||||
{
|
||||
digitalWrite(AIN1, LOW);
|
||||
digitalWrite(AIN2, HIGH);
|
||||
digitalWrite(BIN1, LOW);
|
||||
digitalWrite(BIN2, HIGH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void OpenTB6612FNG::Stop()
|
||||
{
|
||||
digitalWrite(AIN1, LOW);
|
||||
digitalWrite(AIN2, LOW);
|
||||
digitalWrite(BIN1, LOW);
|
||||
digitalWrite(BIN2, LOW);
|
||||
}
|
||||
31
firmwareCarroEsp32/src/OpenTB6612FNG/OpenTB6612FNG.h
Normal file
31
firmwareCarroEsp32/src/OpenTB6612FNG/OpenTB6612FNG.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef OpenTB6612FNG_h
|
||||
#define OpenTB6612FNG_h
|
||||
#include <Arduino.h>
|
||||
#define PWMA 36
|
||||
#define AIN1 39
|
||||
#define AIN2 34
|
||||
#define STBY 35
|
||||
#define BIN1 32
|
||||
#define BIN2 33
|
||||
#define PWMB 25
|
||||
|
||||
const int freq = 5000;
|
||||
const int ledChannel = 0;
|
||||
const int ledChannel2 = 1;
|
||||
const int resolution = 8;
|
||||
|
||||
|
||||
class OpenTB6612FNG{
|
||||
public:
|
||||
OpenTB6612FNG(int TP);
|
||||
|
||||
void MotorIz(int value);
|
||||
void MotorDe(int value);
|
||||
void Motores(int left, int righ);
|
||||
void Forward();
|
||||
void Backward();
|
||||
void Stop();
|
||||
|
||||
};
|
||||
|
||||
# endif
|
||||
7
firmwareCarroEsp32/src/OpenTB6612FNG/keyswords.txt
Normal file
7
firmwareCarroEsp32/src/OpenTB6612FNG/keyswords.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
OpenTB6612FNG KEYWORD1
|
||||
|
||||
MotorIz KEYWORD2
|
||||
MotorDe KEYWORD2
|
||||
Motores KEYWORD2
|
||||
Forward KEYWORD2
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include <Arduino.h>
|
||||
#include "BluetoothSerial.h"
|
||||
#include "carroEsp32.h"
|
||||
#include "OpenTB6612FNG/OpenTB6612FNG.h"
|
||||
|
||||
OpenTB6612FNG misMotores(0);
|
||||
BluetoothSerial ESP_BT; //Object for Bluetooth
|
||||
|
||||
|
||||
@@ -13,7 +15,8 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
misMotores.Forward();
|
||||
misMotores.Motores(255,255);
|
||||
if (ESP_BT.available()) //Check if we receive anything from Bluetooth
|
||||
{
|
||||
//incoming = ESP_BT.read(); //Read what we recevive
|
||||
|
||||
Reference in New Issue
Block a user