hello evryone !
I'm trying to create my library for a robot project with my high school.
Here's the code from the folder of the library.
my arduino code:
#include <robot_sumo.h>
robot_sumo robot(true);
void setup() {
robot.begin(200);
}
void loop() {
}
cpp file:
#include "robot_sumo.h"
// Moteur A
#define pwma 3
#define ain1 9
#define ain2 10
// Moteur B
#define pwmb 5
#define bin1 7
#define bin2 6
#define STBY 8
//capteur ultrason
#define trig 12
#define echo 11
//capteur infrarouge
#define capteur_avant_gauche A2
#define capteur_centre A1
#define capteur_avant_droit A0
#define capteur_arriere_droit A7
#define capteur_arriere_gauche A6
robot_sumo::robot_sumo(bool test = true);
//fonction d'initialisation de tout les pins
void robot_sumo::begin(const int seuil) {
pinMode(pwma, OUTPUT);
pinMode(ain1, OUTPUT);
pinMode(ain2, OUTPUT);
pinMode(pwmb, OUTPUT);
pinMode(bin1, OUTPUT);
pinMode(bin2, OUTPUT);
pinMode(STBY, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(capteur_avant_droit, INPUT);
pinMode(capteur_avant_gauche, INPUT);
pinMode(capteur_centre, INPUT);
pinMode(capteur_arriere_gauche, INPUT);
pinMode(capteur_arriere_droit, INPUT);
int _seuil = seuil;
}
void robot_sumo::AG(int vitesseG) {
if (vitesseG < 0) _vitesseG = (vitesseG - (2 * vitesseG));
if (vitesseG > 0) _vitesseG = vitesseG;
analogWrite(pwma, _vitesseG);
digitalWrite(STBY, HIGH);
if (vitesseG > 0) {
digitalWrite(ain1, HIGH);
digitalWrite(ain2, LOW);
}
if (vitesseG < 0) {
digitalWrite(ain1, LOW);
digitalWrite(ain2, HIGH);
}
}
void robot_sumo::AD(int vitesseD) {
if (vitesseD < 0) _vitesseD = (vitesseD - (2 * vitesseD));
if (vitesseD > 0) _vitesseD = vitesseD;
analogWrite(pwma, _vitesseD);
digitalWrite(STBY, HIGH);
if (vitesseD > 0) {
digitalWrite(bin1, HIGH);
digitalWrite(bin2, LOW);
}
if (vitesseD < 0) {
digitalWrite(bin1, LOW);
digitalWrite(bin2, HIGH);
}
}
void robot_sumo::Stop() {
digitalWrite(ain1, HIGH);
digitalWrite(ain2, HIGH);
digitalWrite(bin1, HIGH);
digitalWrite(bin2, HIGH);
}
float robot_sumo::ultrason() {
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long _duree = pulseIn(echo, HIGH);
float distance = (_duree / 2) / 29.1;
return distance;
}
String robot_sumo::Acouleur() {
int c1 = analogRead(capteur_avant_droit);
int c2 = analogRead(capteur_avant_gauche);
int c3 = analogRead(capteur_centre);
String couleurretenue;
if (c1 > 200 & c2 > 200 & c3 > 200) {
couleurretenue = "Noir";
}
else if (c1 <= 200 || c2 <= 200 || c3 <= 200) {
couleurretenue = "Blanc";
}
return couleurretenue;
}
String robot_sumo::Rcouleur() {
int c4 = analogRead(capteur_arriere_gauche);
int c5 = analogRead(capteur_arriere_droit);
String couleurretenue;
if (c4 > 200 & c5 > 200) {
couleurretenue = "Noir";
}
else if (c4 <= 200 || c5 <= 200) {
couleurretenue = "Blanc";
}
return couleurretenue;
}
.h file:
#ifndef tl
#define tl
#if (ARDUINO >=100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class robot_sumo {
public:
robot_sumo(bool test=true);
// Methods
void begin(const int seuil);
void AG(int vitesseG);
void AD(int vitesseD);
void Stop();
float ultrason();
String Acouleur();
String Rcouleur();
private:
const int _seuil;
int _vitesseG;
int _vitesseD;
long _duree;
};
#endif
and the arduino ide gives me an error :
C:\Users\nathan\AppData\Local\Temp\ccQU5dXf.ltrans0.ltrans.o: In function `_GLOBAL__sub_I_robot':
C:\Users\nathan\Documents\Arduino\test/test.ino:3: undefined reference to `robot_sumo::robot_sumo(bool)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Erreur de compilation pour la carte Arduino Nano
what's wrong ?
I'm Belgian so excuse me if my English is not perfect