Ejemplo/Servo/Knob. Conectamos Ao al cable del medio del servo. Otra a GND y otra a 5v.......etc.
Páginas
▼
lunes, 31 de agosto de 2015
domingo, 30 de agosto de 2015
Curso Arduino Ejemplo 5
Ejemplos/Servo/Swep
Sirve para hacer el efecto del riego por aspersión, va de 0 a 180 grados y retrocediendo hasta 0 grados.
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#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(9); // 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, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(0); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
Sirve para hacer el efecto del riego por aspersión, va de 0 a 180 grados y retrocediendo hasta 0 grados.
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#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(9); // 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, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(0); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
sábado, 29 de agosto de 2015
Curso Arduino práctica 4
Ejemplo/servo/Knob y en él hemos corregido en myservo.write(0)
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#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(9); // 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, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(0); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#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(9); // 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, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(0); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
viernes, 28 de agosto de 2015
Curso CPR - Arduino práctica 3
Modificamos un ejemplo de los más sencillos para que la salida 12 controle en encendido y apagado de un led (protegido con resistencia de 150 ohmnios) cuando el valor del sensor es menor de 15.
Partimos del ejemplo Basic/AnalogReedSerial y le hacemos modificaciones
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(12,OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
if (sensorValue < 15)
{
digitalWrite(12,HIGH);
}
else
{
digitalWrite(12,LOW);
}
}
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
Partimos del ejemplo Basic/AnalogReedSerial y le hacemos modificaciones
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(12,OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
if (sensorValue < 15)
{
digitalWrite(12,HIGH);
}
else
{
digitalWrite(12,LOW);
}
}
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}