martes, 5 de diciembre de 2017

Práctica 16

En esta práctica conoceremos el funcionamiento del servomotor y los usos de este mismo. Este sensor solo se mueve por grados así que conoceremos cuales son estos. 

Materiales:

-Arduino
-Protoboard
-Motor reductor 
-Potenciometro 50k ohm
-Cable Dupont 

Código:

#include<Servo.h>
Servo myServo;
int const PotPin=A5;
int PotVal;
int angle;
void setup(){
myServo.attach(9);
Serial.begin(9600);
}
void loop(){
PotVal=analogRead(PotPin);
Serial.print("PotVal:");
Serial.print(PotVal);
angle=map(PotVal,0,1023,0,179);
Serial.print ("angle= ");
Serial.println (angle);
myServo.write(angle);
delay (15);
}

                                           



                                                   



No hay comentarios:

Publicar un comentario