With all the nice and helpfull replies in mind and after following a few tutorials I came up with these few steps:
#include <legopowerfunctions.h> // Lego PF Library
LEGOPowerFunctions lego(13); // Pin for Lego PF IR Output
//configure the obstacle avoiding sensor
int sensorPinEN = 7; // Common pin for module
int sensorPinLO = 6; // Left Object detected output pin
int sensorPinRO = 5; // Right Object detected output pin
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
// Set the desired pin modes
pinMode(sensorPinEN, OUTPUT);
pinMode(sensorPinLO, INPUT);
pinMode(sensorPinRO, INPUT);
// ready the sensor
digitalWrite(sensorPinEN, HIGH);
}
void loop() {
lego.ComboPWM(PWM_REV2, PWM_FWD2, CH4);
if (digitalRead(sensorPinLO) == HIGH)
lego.ComboPWM(PWM_FWD4, PWM_FWD4, CH4);
if (digitalRead(sensorPinRO) == HIGH)
lego.ComboPWM(PWM_REV4, PWM_REV4, CH4);
}
For the moment I stayed away from boleans etc. I tried to keep it simple for my first run.
After the sketch did verify , I uploaded it and did turn the robot on.
I was very, very pleased with the result, the robot moved nicely in a forward direction and
avoided several objects. Yay! :-)
Ofcourse the sketch was not complete and the robot faced some movement problems, cause of the
lack of code that is missing at this point.
So my next step would be to improve the code.
For my understanding, would I add code to the IF left high and IF right high statements? Or write a new seperate function?
Like:
if (digitalRead(sensorPinLO) == HIGH ( < 5000) <---new timer function less than x seconds
lego.ComboPWM(PWM_FWD4, PWM_FWD4, CH4);
if (digitalRead(sensorPinLO) == HIGH ( > 5000) <---new timer function more than x seconds
lego.ComboPWM(PWM_FWD7, PWM_FWD7, CH4);
I also did try to find some tuts about moving robots around, but many tutorials include the use of a ultrasonic sensor and
ofcourse the code is accordenly for that kind of sensor and not the one I use. Maybe someone knows a tutorial?
My Sensor:
http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=152_156&products_id=589Also if my choice of hardware was not the right one to start with, I would love to hear that also :-) When I did purchase this sensor
I did not know there was an ultrasonic one too. Thanks again for the help, I really enjoyed it when the robot moved like intended
for the first time.
M