RobotArmValgfag_EAL (4 / 5 étapes)

Étape 4: prioriterede

/*

 Controlling a servo position using a potentiometer (variable resistor) by Michal Rinott 
 modified on 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Knob 
 modified on 20 May 2016 by Troels & Jonas, students from Erhvervsakademiet Lillebælt */ 
 #include 
 Servo myservo; // create servo object to control a servo Servo myservo1; // create servo object to control a servo Servo myservo2; // create servo object to control a servo Servo myservo3; // create servo object to control a servo 
 int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin int valop=90; 
 int potpin1 = 1; // analog pin used to connect the potentiometer int val1; // variable to read the value from the analog pin int valop1=90; 
 int potpin2 = 2; // analog pin used to connect the potentiometer int val2; // variable to read the value from the analog pin int valop2=90; 
 int potpin3 = 3; // analog pin used to connect the potentiometer int val3; // variable to read the value from the analog pin int valop3=90; 
 #define trigPin 13 #define echoPin 12 #define led 10 #define led2 11 
 void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo1.attach(3); // attaches the servo on pin 10 to the servo object myservo2.attach(5); // attaches the servo on pin 5 to the servo object myservo3.attach(6); // attaches the servo on pin 6 to the servo object 
 pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(led, OUTPUT); pinMode(led2, OUTPUT); 
 Serial.begin(9600); } 
 void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) // val = map(val, 0, 1023, 0, 1023); //Serial.print("valop_"); //Serial.println(valop); // waits for the servo to get there 
 if (val<600&&val>300){ myservo.write (valop=valop); delay(10); //Serial.print("val_"); //Serial.println(val); } 
 if (val>600&&val<1200){ myservo.write (valop=valop +3); delay(10); } 
 if (val<300&&val>1){ myservo.write (valop=valop -3); delay(10); } 
 val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023) //val = map(val, 0, 1023, 0, 1023); if (val1<600&&val1>400){ myservo1.write (valop1=valop1); delay(20); //Serial.print("val1_"); //Serial.println(val1); delay (10); } 
 if (val1>600&&val1<1200){ myservo1.write (valop1=valop1 +3); delay(10); 
 } 
Si (val1 < 300 & & val1 > 1) {myservo1.write (valop1 = valop1 -3); delay(10) ; if (val1<300&&val1>1){ myservo1.write (valop1=valop1 -3); delay(10); } 
 //Serial.print("valop1_"); //Serial.println(valop1); 
val2 = analogRead(potpin2) ; lit la valeur de la //val potentiomètre (valeur comprise entre 0 et 1023) = carte (val, 0, 1023, 0, 1023) ; Si (val2 < 600 & & val2 > 400) {myservo2.write (valop2 = valop2); delay(20); / / Serial.print("val2_"); / / Serial.println(val2) ; val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023) //val = map(val, 0, 1023, 0, 1023); if (val2<600&&val2>400){ myservo2.write (valop2=valop2); delay(20); //Serial.print("val2_"); // Serial.println(val2); } 
 if (val2>600&&val2<1200){ myservo2.write (valop2=valop2 +3); delay(10); 
 } 
Si (val2 < 300 & & val2 > 1) {myservo2.write (valop2 = valop2 -3); delay(10) ; if (val2<300&&val2>1){ myservo2.write (valop2=valop2 -3); delay(10); } 
 //Serial.print("valop2_"); //Serial.println(valop2); 
val3 = analogRead(potpin3) ; lit la valeur de la //val potentiomètre (valeur comprise entre 0 et 1023) = carte (val, 0, 1023, 0, 1023) ; Si (val3 < 600 & & val3 > 400) {myservo3.write (valop3 = valop3); delay(20) ; Serial.Print("val3_") ; Serial.println(val3) ; val3 = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023) //val = map(val, 0, 1023, 0, 1023); if (val3<600&&val3>400){ myservo3.write (valop3=valop3); delay(20); Serial.print("val3_"); Serial.println(val3); } 
 if (val3>600&&val3<1200){ myservo3.write (valop3=valop3 +3); delay(10); 
 } 
Si (val3 < 300 & & val3 > 1) {myservo3.write (valop3 = valop3 -3); delay(10) ; if (val3<300&&val3>1){ myservo3.write (valop3=valop3 -3); delay(10); } 
 Serial.print("valop3_"); Serial.println(valop3); 
longue durée, distance ; digitalWrite (trigPin, basse) ; Ajouté cette ligne delayMicroseconds(2) ; Ajouté cette ligne digitalWrite (trigPin, HIGH) ; delayMicroseconds(1000) ; -Suppression de cette ligne delayMicroseconds(10) ; Ajouté cette ligne digitalWrite (trigPin, basse) ; durée = pulseIn (echoPin, HIGH) ; distance = (durée/2) / 29,1 ; Si (distance < 4) {/ / c’est où la LED on/off arrive digitalWrite(led,HIGH); / / lorsque le rouge condition est remplie, la LED verte doit s’éteindre digitalWrite(led2,LOW) ; long duration, distance; digitalWrite(trigPin, LOW); // Added this line delayMicroseconds(2); // Added this line digitalWrite(trigPin, HIGH); // delayMicroseconds(1000); - Removed this line delayMicroseconds(10); // Added this line digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance < 4) { // This is where the LED On/Off happens digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off digitalWrite(led2,LOW); } else { digitalWrite(led,LOW); digitalWrite(led2,HIGH); } if (distance >= 200 || distance <= 0){ Serial.println("Out of range"); } else { Serial.print(distance); Serial.println(" cm"); } delay(500); else {digitalWrite(led,LOW) ; digitalWrite(led2,HIGH) ; } Si (distance > = 200 || distance < = 0) {Serial.println ("out of range") ;else {Serial.print(distance) ; Serial.println ("cm") ;
			
          

Articles Liés