I´ve done two sketches, one for a sensor and another one for a servo. But i don´t know if a can mix them in one sketch so i can use just one Arduino. Thanks a lot.
This is the sensor´s code: (it´s an easy one)
const int SENSOR = 0;
int val = 0;
void setup () {
Serial.begin(9600);
}
void loop () {
val = analogRead (SENSOR);
Serial.println (val);
delay (100);
}
And this servo´s:
#include <Servo.h>
Servo servoMain; // Define nuestro servo
void setup()
{
servoMain.attach(10); // servo en pin 10PWM
void loop()
{
servoMain.write(45); // Gira 45 grados
delay(1000); // espera un segundo
servoMain.write(0); // gira 0 grados
delay(1000); // espera un segundo
servoMain.write(90); // gira al centro, 90 grados
delay(1000); // espera un segundo
servoMain.write(135); // gira 135 grados
delay(1000); // espera un segundo
servoMain.write(180); // gira 180 grados
delay(1000); // espera un segundo
delay(1000); // espera un segundo
}
I´ve tried to mix them apparently in a correct way but when i open Processing the sensor doesn´t run. Thank you very much again.
Moderator edit: Replaced italics tags with CODE TAGS
Sensors don't typically run.
I assume you mean "the sensor doesn't produce results every 1/10th of a second as it did before, but only every six seconds"
Yes, that's what I'd expect, which is why you need to get rid of the delays as they are written now.
You could write your own version of "delay" which works in 100 millisecond chunks, reading and printing the sensor value every 100 milliseconds (quick-and-fairly-dirty method), or you could take a look at the blink without delay example which came with the IDE.