Projet

Général

Profil

UtilisationMoteur » Historique » Version 3

Alexandre FIALE, 17/03/2016 15:34

1 1 Alexandre FIALE
UtilisationMoteur
2
=================
3
4
Sketch
5
------
6
7
Voici le sketch utilisé pour l'atelier :
8
9
    int motor1P1  = 2; 
10
    int motor1P2  = 3;
11
    int motor1PWM = 9;
12
    int delai     = 2000;
13
    void setup() {
14
        Serial.begin(9600);
15
        pinMode(motor1P1, OUTPUT);
16
        pinMode(motor1P2, OUTPUT);
17
        pinMode(motor1PWM, OUTPUT);
18
    }
19
20
    void loop() {
21
        delay(delai);
22
        forward();
23
        delay(delai);
24
        backward();
25
        delay(delai);
26
        stopMotor();
27
        delay(delai);
28
    }
29
30
    void forward() {
31
        int i =0;
32
        digitalWrite(motor1P1, HIGH);
33
        digitalWrite(motor1P2, LOW);
34
    
35
        for(i=0; i<255; i++) {
36
            analogWrite(motor1PWM, i);
37
            Serial.print('speed');
38
            Serial.println(i);
39
        }
40
    }
41
42
    void backward() {
43
        int i =0;
44
        digitalWrite(motor1P1, LOW);
45
        digitalWrite(motor1P2, HIGH);
46
    
47
        for(i=0; i<255; i++) {
48
            analogWrite(motor1PWM, i);
49
        }
50
    }
51
52
    void stopMotor() {
53
        digitalWrite(motor1P1, LOW);
54
        digitalWrite(motor1P2, LOW);
55
    }
56
57
58
Schéma de cablage
59
------
60 3 Alexandre FIALE
61
![schéma](riorand-L298N copie.jpg )