}
#pragma config(Sensor, S1, EOPD, sensorAnalogActive)
#include "drivers/HTEOPD-driver.h" // download and include drivers
task main() {
int raw = 0;
int distance = 0;
while(nNxtButtonPressed != kEnterButton) {
// Read the raw sensor value
raw = HTEOPDreadRaw(EOPD);
if (raw> 70) // if raw > 70 then distance = 1
{
distance = 1; // distance = distance between sensor and obstacle
}
if (raw< 70) // if raw < 70 then distance = 2
{
distance = 2;
}
if (distance == 1)
{
motor[motorA]=0;
motor[motorB]=0;
}
if (distance == 2)
{
motor[motorA]=20;
motor[motorB]=20;
}
}
}
{code} |