rendered paste body#include "stdio.h"
#include "stdlib.h"
#define RTHRESH_BLACK 50
#define LTHRESH_BLACK 50
#define RTHRESH_GREY 40
#define LTHRESH_GREY 40
int LSENSOR=1;
int RSENSOR=2;
int retval=0;
int nothing;
void untilfunction(int obst)
{
switch (obst)
{
/* The first selection */
/* turn left opun black line */
case 1:
if (LSENSOR<=LTHRESH_BLACK || RSENSOR<=RTHRESH_BLACK)
{ retval=1; }
else
{ retval=0; }
break;
/* pre-gate selection */
/* returns true wgeb both sensors hit grey */
case 2:
printf ("if %d<=%d",LSENSOR,LTHRESH_GREY);
if (LSENSOR<=LTHRESH_GREY && RSENSOR<=RTHRESH_GREY)
{ retval=1; }
else
{ retval=0; }
break;
}
}
void initsensors()
{
/*
SetSensor(SENSOR_1,SENSOR_LIGHT);
SetSensor(SENSOR_2,SENSOR_TOUCH);
SetSensor(SENSOR_3,SENSOR_LIGHT);
SetSensorMode(SENSOR_1, SENSOR_MODE_PERCENT);
SelectDisplay(DISPLAY_SENSOR_1);
*/
}
void turnleft()
{
/*
OnFwd(LMOTOR);
OnRev(RMOTOR);
Wait(200);
Off(OUT_A+OUT_C);
*/
}
void leftpath() {
printf("PATH: %s SENSOR: %d\n", "LEFT ", LSENSOR );
}
void rightpath() {
printf("PATH: %s SENSOR: %d\n", "RIGHT ", LSENSOR);
}
void followline(int untilobst)
{
while (1)
{
untilfunction(untilobst);
if (retval==1) { printf("return\x0a"); return; }
{
if (LSENSOR<=LTHRESH_BLACK)
{
rightpath();
}
else if (RSENSOR<=RTHRESH_BLACK)
{
printf("%s", "HELLO");
leftpath();
}
else { printf("CURRENT PATH: %s SENSOR: %d\x0a", "PREVIOUS ",LSENSOR); }
if (LSENSOR==49) { RSENSOR=51; }
LSENSOR-=1;
RSENSOR-=1;
}
}
printf("grey sensors hit\x0a");
}
int main()
{
LSENSOR=60;
RSENSOR=60;
followline(2);
}