Skip to content

Commit

Permalink
Merge pull request #11 from UlmerMan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
UlmerMan authored Mar 24, 2023
2 parents 6cb4693 + 1ed46f4 commit d4ab8f4
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 102 deletions.
27 changes: 6 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
# About

This is a library for Elegoo Smart Car Robot Kit.

## Getting Started

### Commands

| **Command** | **Explenation** |
| :----------------------------------------------------------: | ------------------------------------------------------------ |
| Constructor<br />e. g. elegoo car(version) | You have to put the version in quotes in the brackets. You can see the Supported Versions in the table below. |
| forward() <br />backward()<br> left()<br> right()<br> stop() | These arguments explain themselves. Into the brackets you can put a number between 1 and 256 for the speed. The default speed is 255. |
| forwardT() <br> backwardT() <br> leftT() <br>rightT() | The arguments function just like the others but you have to put the time and the speed into the brackets. <br> With a syntax like this: <br> ``` car.forwardT(SPEED, TIME); ``` <br>You can choose a number between 1 and 255. |
| getDistance() | This is a function to get the distance from the Ultrasonic sensor. It returns it as an Integer. |

## Supported Versions

| Version | Comment |
| ------- | ----------------------------------------------------- |
| v1 | e. g. elegoo car ("v1") |
| v2 | e. g. elegoo car ("v2") |
| v3 | e. g. elegoo car ("v3") |
| v4.0 | e. g. elegoo car ("v4.0") **!!!work in progress!!!** |
| v4.1 | e. g. elegoo car ("v4.1") **!!!work in progress!!!** |
| v4.2 | e. g. elegoo car ("v4.2") **!!!work in progress!!!** |

| **Command** | **Explenation** |
|:---:|---|
| car.init() | This argument is needed in every code. It is to initialize the the library. In the brackets you can put the version of your robot. The default version is 3. |
| car.forward()<br> car.backward()<br> car.left()<br> car.right()<br> car.stop() | These arguments explain themself. Into the brackets you can put a number between 1 and 256 for the speed. The default speed is 255. |
| car.forwardT() <br> car.backwardT() <br> car.leftT() <br> car.rightT() | The arguments function just like the others but you have to put the time and the speed into the brackets. <br> With a syntax like this: <br> ``` car.forwardT(SPEED, TIME); ``` <br>You can choose a number between 1 and 255. |
| car.getDistance() | This is a function to get the distance from the Ultrasonic sensor. It returns it as an Integer. |


<!-- CONTRIBUTING -->

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
Expand Down
7 changes: 5 additions & 2 deletions examples/FirstSteps/FirstSteps.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <car.h>
#include <elegoo.h>

#define version 3

elegoo car(version);

void setup(){
Serial.begin(9600); //Begin a serial connection
car.init(); //Initialze car. Please put the Version of your robot into the brackets
}


Expand Down
6 changes: 5 additions & 1 deletion examples/ObstacleAvoidance/ObstacleAvoidance.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
//www.elegoo.com

#include <car.h>
#include <elegoo.h>
#include <Servo.h> //servo library

#define version 3

elegoo car(version);
Servo myservo; // create servo object to control servo

int Echo = A4;
Expand Down
92 changes: 67 additions & 25 deletions src/Elegoo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,97 @@

// Constructor

elegoo::elegoo(int vers)
elegoo::elegoo(String version)
{
if (vers == 1)
if (version == "v1")
{
vers = version;
vers = 1;
in1 = 9;
in2 = 8;
in3 = 7;
in4 = 6;
ENA = 10;
ENB = 5;
Setup();
}
if (vers == 2)
if (version == "v2")
{
vers = version;
vers = 1;
in1 = 6;
in2 = 7;
in3 = 8;
in4 = 9;
ENA = 5;
ENB = 11;
Setup();
}
if (vers == 3)
if (version == "v3")
{
vers = version;
vers = 1;
in1 = 7;
in2 = 8;
in3 = 9;
in4 = 11;
ENA = 5;
ENB = 6;
Setup();
}
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(LED, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(LineTeacking_Pin_Right, INPUT);
pinMode(LineTeacking_Pin_Middle, INPUT);
pinMode(LineTeacking_Pin_Left, INPUT);
Servo libServo;
libServo.attach(3);
IRbegin();
if (version == "v4")
{
PWMA = 5;
PWMB = 6;
AIN1 = 8;
BIN1 = 7;
Setup();
}
if (version == "v4.1")
{
PWMA = 5;
PWMB = 6;
AIN1 = 7;
BIN1 = 8;
Setup();
}
if (version == "v4.2")
{
PWMA = 5;
PWMB = 6;
AIN1 = 7;
BIN1 = 8;
Setup();
}
}

// IRrecv irrecv(RECV_PIN);
// irrecv->begin(RECV_PIN, LED);
void elegoo::Setup()
{
if (vers <= 3)
{
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(LED, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(LineTeacking_Pin_Right, INPUT);
pinMode(LineTeacking_Pin_Middle, INPUT);
pinMode(LineTeacking_Pin_Left, INPUT);
Servo libServo;
libServo.attach(3);
IRbegin();
}
if (vers >= 4)
{
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(PIN_Voltage, INPUT);
pinMode(PIN_LTL, INPUT);
pinMode(PIN_LTM, INPUT);
pinMode(PIN_LTR, INPUT);
}
}
38 changes: 35 additions & 3 deletions src/Elegoo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#define echo A4
#define trig A5

#define defaultVersion 3
#define defaultSpeed 255

//-------Line Tracking Pins--------//
#define LineTeacking_Pin_Right 10
#define LineTeacking_Pin_Middle 4
#define LineTeacking_Pin_Left 2
#define PIN_LTL A2
#define PIN_LTM A1
#define PIN_LTR A0

//---------- IR REMOTE -------------//
#define RECV_PIN 12 //Infrared signal receiving pin
Expand All @@ -41,11 +43,21 @@
#define KEY_STAR 16728765
#define KEY_HASH 16732845

#define PIN_Voltage A3

/*
#define v1 1
#define v2 2
#define v3 3
#define v4 4
#define v41 5
#define v42 6
*/

class elegoo
{
public:
elegoo(int vers); //Constructor
elegoo(String version); //Constructor
void forward(int speed);
void back(int speed);
void left(int speed);
Expand Down Expand Up @@ -87,6 +99,8 @@ class elegoo
bool forwardDistance(int distance);
void backDistance(int distance, int speed);
void backDistance(int distance);
float getVoltage();

private:
Servo *libServo;
int in1 = 0;
Expand All @@ -95,8 +109,26 @@ class elegoo
int in4 = 0;
int ENA = 0;
int ENB = 0;
int version;

/*
Version Controller
1 = v1
2 = v2
3 = v3
4 = v4.0
5 = v4.1
6 = v4.2
*/

int vers;
int keepDistanceValue = 10;
int PWMA;
int PWMB;
int AIN1;
int BIN1;

private:
void Setup();
};

class controler
Expand Down
Loading

0 comments on commit d4ab8f4

Please sign in to comment.