#include <Servo.h>
const int analogInPin = A0;
const int pinservo = 9;
int sensorValue = 0;
int outputValue = 0;
int angulo[10] = {5,10,45,90,25,12,135,75,180,110};
char msg[4] = {0x48,0x4F,0x4C,0x41};
String msg2 = "HOLA";
Servo myservo;
void setup() {
Serial.begin(9600);
myservo.attach(pinservo);
}
void loop() {
Serial.println(msg2);
delay(3000);
/* Serial.println("Con Bucle For al Revés: ");
for (int i = 9; i >= 0; i--) { // i-- -> i=i+1;
myservo.write(angulo[i]);
Serial.print("angulo[");
Serial.print(i);
Serial.print("]=");
Serial.println(angulo[i]);
delay(2000);
}
Serial.println("Con Bucle While al Revés: ");
int i = 9;
while (i >= 0) {
myservo.write(angulo[i]);
Serial.print("angulo[");
Serial.print(i);
Serial.print("]=");
Serial.println(angulo[i]);
delay(2000);
i--;
}*/
}
/*#include <Servo.h>
// These constants won't change. They're used to give names to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int pinservo = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int angulo[10] = {5,10,45,90,25,12,135,75,180,110} ;
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
myservo.attach(pinservo);
}
void loop() {
Serial.println("Con Bucle For: ");
for (int i=0;i<10;i++){ //bucle autoincrementable
myservo.write(angulo[i]);// manda el ángulo al servo
Serial.print("angulo["); //imprime en el serial, el ángulo
Serial.print(i);
Serial.print("]=");
Serial.println(angulo[i]);
delay(2000);
}
Serial.println("Con Bucle While: ");
int i = 0;
while(i<10){
myservo.write(angulo[i]);// manda el ángulo al servo
Serial.print("angulo["); //imprime en el serial, el ángulo
Serial.print(i);
Serial.print("]=");
Serial.println(angulo[i]);
delay(2000);
i++;
}
//La tarea de Brandon, va consistir en hacer que el bucle se desplace inversamente
//o sea que se desplace de 9 a 0
/*
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 180);
// change the analog out value:
//analogWrite(pinservo, outputValue);
myservo.write(outputValue);
// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);*/