Hello,
I'm new into working with the arduino , but i like it a lot. So i'm having a problem with a piece of code. It contist of 2 functions. The first one is driving three servos. This just works fine. Then i add another function, this one is for the distance sensor. If i just run the distance function alone, it gives the disctance on the screen. (pretty correct). But if i add the servofunction, then there is trouble: readout of the distance servo gives just plain zero :-/ :-/
The distance sensor is working with I2C. Hers the complete code:
#include <Servo.h>
/* Distancesensor Marcel vd Kamp
Works through I2S communication.
SDA on analog in P4 (use black for ground, Red for 5V, Yellow for signal
SCL on analog in P5 (only use Yellow for signal)
*/
#include "Wire.h"
#include "SRF02.h"
SRF02 sensor(0x70, SRF02_CENTIMETERS);
unsigned long nextPrint = 0;
Servo myservoM; // create servo object to control a servo
Servo myservoR;
Servo myservoL;
int posM = 98; // variable to store the servo position
int posRL = 90;
void setup()
{
myservoM.attach(8); // attaches the servo on pin 9 to the servo object
myservoR.attach(9);
myservoL.attach(10);
Serial.begin(9600);
Wire.begin();
}
void loop()
{
Measure();
Move();
}
void Move()
{
for(posM = 88; posM < 108; posM += 1)
{
myservoM.write(posM);
myservoL.write(posM);
myservoR.write(posM);
delay(30);
}
for(posM = 108; posM>=88; posM-=1)
{
myservoM.write(posM);
myservoL.write(posM);
myservoR.write(posM);
delay(30);
}
}
void Measure()
{
SRF02::update();
if (millis() > nextPrint)
{
Serial.println(sensor.read());
nextPrint = millis () + 100;
}
}
Just running: measure: getting good readings
running measure + move : no readings, getting zeros
Anyone who can help me out ?
greetings,
Marcel