You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

EOPD:n käyttöönotto

Tämä esimerkki pysäyttää robotin liikkeen kun etäisyys on tarpeeksi pieni.

#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;

      }
    }
  }
  • No labels
You must log in to comment.