Bonjour
j'ai un projet en tpe
je vous explique le projet Arduino
c'est un bras articuler qui dois attraper un jeton de poker pour le ranger dans une boite en fonction de sa couleur
par exemple: le bras se positionne en position initiale puis se position sur la position 1 emplacement du premier jeton et capte la couleur du jeton si le jeton est rouge il le met dans la boite rouge sinon vert boite verte ... puis il se positionne a la position 2 et capte la couleur ...
le bras articuler à 6 moteurs que je peut piloter la n'est pas mon problème mon problème est le capteur
Voici mon code pour piloter les moteur
et voici le code pour le capteur
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 #include <Servo.h> Servo myservo; //declaration du moteur Servo myservo2; //les deux moteurs en bas Servo myservo3; Servo myservo4; Servo myservo5; void setup() { myservo.attach(9); myservo.write(90); //rotation en degres du moteur delay(1000); myservo2.attach(11); myservo2.write(90); delay(1000); myservo3.attach(10); myservo3.write(90); delay(1000); myservo4.attach(6); myservo4.write(90); delay(1000); myservo5.attach(5); myservo5.write(30); delay(2000); } void loop() { myservo.attach(9); myservo.write(45); delay(1000); myservo2.attach(11); myservo2.write(45); delay(1000); myservo3.attach(10); myservo3.write(45); delay(1000); myservo4.attach(6); myservo4.write(45); delay(1000); myservo5.attach(5); myservo5.write(45); }
Mon problème est que j'aimerais que le capteur soit utiliser après que les moteurs soit positionner mais je ne voit pas comment merci que votre aide.
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
77
78
79
80
81
82
83
84 int s0=3,s1=4,s2=5,s3=6;//branchements entrées capteurs int out=2;//branchement sortie capteur int flag=0; //variable pour distinguer les 3 cas int LedR=9; byte counter=0; byte countR=0,countG=0,countB=0; void setup() { Serial.begin(115200); pinMode(s0,OUTPUT); pinMode(s1,OUTPUT); pinMode(s2,OUTPUT); pinMode(s3,OUTPUT); pinMode(LedR,OUTPUT); } void TCS() { flag=0; digitalWrite(s1,HIGH); digitalWrite(s0,LOW); //frequence 20% digitalWrite(s2,LOW);// s2 = s3 =0 = RED digitalWrite(s3,LOW); attachInterrupt(0, ISR_INTO, CHANGE); timer0_init(); } void ISR_INTO() { counter++; //couter=counter+1 } void timer0_init(void) { TCCR2A=0x00; TCCR2B=0x07; //the clock frequency source 1024 points TCNT2= 100; //10 ms overflow again TIMSK2 = 0x01; //allow interrupt } int i=0; ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function { TCNT2=100; flag++; if(flag==1) { countR=counter; Serial.print("red="); Serial.println(countR,DEC); digitalWrite(s2,HIGH); digitalWrite(s3,HIGH); } else if(flag==2) { countG=counter; Serial.print("green="); Serial.println(countG,DEC); digitalWrite(s2,LOW); digitalWrite(s3,HIGH); } else if(flag==3) { countB=counter; Serial.print("blue="); Serial.println(countB,DEC); Serial.println("\n"); digitalWrite(s2,LOW); digitalWrite(s3,LOW); } //if(countR > countB && countR > countG) //{digitalWrite(LedR,HIGH); } else if(flag==4) { flag=0; } counter=0; } void loop() { TCS(); while(1); }
Partager