ok, so im building a soccer robot, and currently while im programmig it im using serial.read() to make sure everything is functioning normal.
My problem is that after about a minute it pronts out something like this
Output: Voltage: 0.10 Volts -noball
Output: Voltage: 0.08 Volts -noball
Output: Voltage: 0.07 Volts -noball
Output: Voltage: 0.05 Volts -noball
Output: Voltage: 0.08 Volts -noball
Output: Voltage: 0.1
and then stops reporting any more values. My code is this
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
int irPin0 = 0; // the cell and 10K pulldown are connected to a0
int irReading0; // the analog reading from the analog resistor divider
int irPin1 = 0; // the cell and 10K pulldown are connected to a0
int irReading1; // the analog reading from the analog resistor divider
int irPin2 = 0; // the cell and 10K pulldown are connected to a0
int irReading2; // the analog reading from the analog resistor divider
float Res0=1.0;// Resistance in the circuit of sensor 0 (KOhms)
// depending of the Resistance used, you could measure better at dark or at bright conditions.
// you could use a double circuit (using other LDR connected to analog pin 1) to have fun testing the sensors.
// Change the value of Res0 depending of what you use in the circuit
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
#include <CompactQik2s9v1.h>
#include <NewSoftSerial.h>
#define rxPin1 3
#define txPin1 4
#define rstPin1 5
#define rxPin2 6
#define txPin2 7
#define rstPin2 8
NewSoftSerial mySerial1 = NewSoftSerial(rxPin1, txPin1);
CompactQik2s9v1 motor1 = CompactQik2s9v1(&mySerial1,rstPin1);
NewSoftSerial mySerial2 = NewSoftSerial(rxPin2, txPin2);
CompactQik2s9v1 motor2 = CompactQik2s9v1(&mySerial2,rstPin2);
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(irPin0, INPUT);
pinMode(irPin1, INPUT);
pinMode(irPin2, INPUT);
// initialize serial communication:
Serial.begin(9600);
mySerial1.begin(9600);
mySerial2.begin(9600);
motor2.begin();
motor1.begin();
motor1.stopBothMotors();
motor2.stopBothMotors();
}
void loop() {
irReading0 = analogRead(irPin0); // Read the analogue pin
float Vout0=irReading0*0.0048828125; // calculate the voltage
irReading1 = analogRead(irPin1);
irReading2 = analogRead(irPin2);
Serial.print("Output: ");
Serial.print("Voltage: "); // Print the calculated voltage returned to pin 0
Serial.print(Vout0);
Serial.print(" Volts\t");
if (irReading0 > 100) { // check left Ir sensor.
Serial.print(" - BALLLEFT"); // ir 1
motor1.motor0Reverse(200);
motor1.motor1Forward(200);
delay(100);
motor1.stopBothMotors();
motor2.stopBothMotors();
delay(100);
}
else{
if (irReading1 > 100){
Serial.print(" - BALLFRONT"); //ir 2
delay(100);
}
else{ if (irReading2 > 100){
Serial.print(" - BAllRIGHT");// ir 3
motor1.motor0Forward(200);
motor1.motor1Reverse(200);
delay(100);}
else{
Serial.println("-noball");
loop();
}}}
Serial.
delay(100);//end of button loop
}
from my other testings i have found that each part of the program works fine, it is only this one bit that im having trouble with, and i cant keep working on my robot without this.
thanks for any help offered
Jake