Cintillo Institucional
Diferencias entre las revisiones 11 y 12
Versión 11 con fecha 2011-05-19 12:53:20
Tamaño: 1053
Comentario:
Versión 12 con fecha 2011-05-19 15:49:17
Tamaño: 1941
Comentario:
Los textos eliminados se marcan así. Los textos añadidos se marcan así.
Línea 14: Línea 14:

{{{
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>
 
Servo myservo; // 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
 
void setup()
{
  myservo.attach(7); // attaches the servo on pin 9 to the servo object
}
 
void loop()
{
  val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val); // sets the servo position according to the scaled value
  delay(15); // waits for the servo to get there
}
}}}

wiki comunidad

Proyecto Hardware Libre Cenditel

Página Cenditel

wiki Cenditel

Plataforma de Desarrollo Colaborativo

Curso Sensibilización Hardware Libre (Unidad 002)

logohl.png logohl.png logohl.png

003/01 Actividad 005

Trabajo con sevo motores,

// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include <Servo.h> 
 
Servo myservo;  // 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 
 
void setup() 
{ 
  myservo.attach(7);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
} 

hlpd/curso_arduino/uni00301 (última edición 2011-06-13 21:58:17 efectuada por _desactivada_csoto)