Bonjour ;



le code suivant marche tres bien sauf que j'arrive a cree un seul objet , si je rajoute un 2em le premier sera ecraer merci de m aider .

MD.h

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
 
#ifndef MD_h
#define MD_h
 
#include "Arduino.h"
 
class Kouka
{
	private:
    int ena;
    int in1;
    int in2;
    int in3;
    int in4;
    int enb;
	int speed1;
	int speed2;
  public:
    static const int MOTOR_A = 0;
    static const int MOTOR_B = 1;
    Kouka(int wena, int win1, int win2, int win3, int win4, int wenb, int wspeed1 , int wspeed2);
    void Start_Motor();
    void Drive_Motor(int motor_index, int speed);
    void Setup_Motor(int motor_index, int state1, int state2);
    void Forward(int motor_index);
    void Stop(int motor_index);
	void Speed(int motor_index,int speed);
    void Backward(int motor_index);
 
};
 
#endif
MD.cpp

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
 
 
#include "MD.h"
 
struct Motor {
  int in1;
  int in2;
  int pwn;
  int speed;
};
 
Motor titi[2];
 
Kouka::Kouka(int wena, int win1, int win2, int win3, int win4, int wenb, int wspeed1,int wspeed2) {
  ena=wena;
  in1=win1;
  in2=win2;
  in3=win3;
  in4=win4;
  enb=wenb;
  speed1=wspeed1;
  speed2=wspeed2;
  pinMode (wena, OUTPUT);
  pinMode (win1, OUTPUT);
  pinMode (win2, OUTPUT);
  pinMode (win3, OUTPUT);
  pinMode (win4, OUTPUT);
  pinMode (wenb, OUTPUT);
 
  titi[0].in1 = win1;
  titi[0].in2 = win2;
  titi[0].pwn = wena;
  titi[0].speed = wspeed1;
  titi[1].in1 = win3;
  titi[1].in2 = win4;
  titi[1].pwn = wenb;
  titi[1].speed = wspeed2;
}
 
void Kouka::Start_Motor() {
 this-> Drive_Motor(MOTOR_A,titi[0].speed);
  this->Drive_Motor(MOTOR_B,titi[1].speed);
}
 
void Kouka::Speed(int motor_index , int speed) {
   analogWrite(titi[motor_index].pwn,speed);
 
 
}
 
void Kouka::Drive_Motor(int motor_index,int speed) {
  analogWrite(titi[motor_index].pwn,speed);
}
 
void Kouka::Forward(int motor_index) {
  this->Setup_Motor(motor_index,HIGH,LOW);
  this->Start_Motor();
 
}
 
void Kouka::Backward(int motor_index) {
  this->Setup_Motor(motor_index,LOW,HIGH);
  this->Start_Motor();
}
 
void Kouka::Stop(int motor_index) {
  this->Setup_Motor(motor_index,LOW,LOW);
  this->Start_Motor();
 
}
 
void Kouka::Setup_Motor(int motor_index, int state1, int state2) {
  digitalWrite(titi[motor_index].in1, state1);
  digitalWrite(titi[motor_index].in2, state2);
}
le Sketch : Arduino :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
 
 
#include <MD.h>
const int ENA = 8;
const int IN1 = 22;
const int IN2 = 23;
const int IN3 = 24;
const int IN4 = 25;
const int ENB = 9;
const int ENC = 10;
const int IN11 = 26;
const int IN22 = 27;
const int IN33 = 28;
const int IN44 = 29;
const int END = 11;
int speed1=150;
int speed2=150;
int speed3=50;
int speed4=50;
Kouka Shlied1(ENC,IN11,IN22,IN33,IN44,END,speed3,speed4);
Kouka Shiled2(ENA,IN1,IN2,IN3,IN4,ENB,speed1,speed2);
void setup() {
  // put your setup code here, to run once:
    Shlied1.Stop(0);
    Shlied1.Stop(1);
    Shlied2.Stop(0);
    Shlied1.Stop(1);
 
}
void loop() {
  // put your main code here, to run repeatedly:
 Shlied1.Forward(1);
 Shlied1.Forward(0);
 Shlied2.Forward(1);
 Shlied2.Forward(0);
 
 
 
delay(5000);
     Shlied1.Stop(0);
    Shlied1.Stop(1);
    Shlied1Stop(0);
    Shlied1.Stop(1);
 
delay(2000);
 
}