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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#define Photoresistance_droite A0
#define Photoresistance_gauche A1
#define Photoresistance_haut A2
// #define mot1
// #define mot2
#define In1 5 // mot 1
#define In2 6 // mot 1
#define In3 2 // mot 2
#define In4 3 // mot 2
boolean tourne_haut;
boolean tourne_droite;
boolean tourne_gauche;
boolean tourne_bas;
int Droite;
int Gauche;
int Haut;
//int Tampon=30;
void setup() {
pinMode(Photoresistance_droite,INPUT);
pinMode(Photoresistance_gauche,INPUT);
pinMode(Photoresistance_haut,INPUT);
pinMode (In1,OUTPUT);
pinMode (In2,OUTPUT);
pinMode (In3,OUTPUT);
pinMode (In4,OUTPUT);
}
void loop()
{
Droite=analogRead(Photoresistance_droite);
Gauche=analogRead(Photoresistance_gauche);
Haut=analogRead(Photoresistance_haut);
if ( Droite > Gauche)
{
tourne_droite=1;
}
else
{
tourne_droite=0;
}
if (Gauche > Droite)
{
tourne_gauche=1;
}
else
{
tourne_gauche=0;
}
if ( Haut < (Gauche + Droite) / 2)
{
tourne_bas=1;
}
else
{
tourne_bas=0;
}
if (Haut > (Gauche + Droite) / 2)
{
tourne_haut=1;
}
else
{
tourne_haut=0;
}
if (tourne_droite=1);
digitalWrite(In1,HIGH);
digitalWrite(In2,LOW);
digitalWrite(In3,LOW);
digitalWrite(In4,LOW);
if (tourne_droite=0);
digitalWrite(In1,LOW);
digitalWrite(In2,LOW);
digitalWrite(In3,LOW);
digitalWrite(In4,LOW);
if (tourne_gauche=1);
digitalWrite(In1,LOW);
digitalWrite(In2,HIGH);
digitalWrite(In3,LOW);
digitalWrite(In4,LOW);
if (tourne_gauche=0);
digitalWrite(In1,LOW);
digitalWrite(In2,LOW);
digitalWrite(In3,LOW);
digitalWrite(In4,LOW);
if (tourne_bas=1);
digitalWrite(In1,LOW);
digitalWrite(In2,LOW);
digitalWrite(In3,HIGH);
digitalWrite(In4,LOW);
if (tourne_bas=0);
digitalWrite(In1,LOW);
digitalWrite(In2,LOW);
digitalWrite(In3,LOW);
digitalWrite(In4,LOW);
if (tourne_haut=1);
digitalWrite(In1,LOW);
digitalWrite(In2,LOW);
digitalWrite(In3,LOW);
digitalWrite(In4,HIGH);
if (tourne_haut=0);
digitalWrite(In1,LOW);
digitalWrite(In2,LOW);
digitalWrite(In3,LOW);
digitalWrite(In4,LOW);
delay(10);
} |
Partager