Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

EOPD:n

...

käyttöönotto

...

Tämä

...

esimerkki

...

pysäyttää

...

robotin

...

liikkeen

...

kun

...

etäisyys

...

on

...

tarpeeksi

...

pieni.

{
Code Block
}
#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}