IR Seekerin käyttöönotto
Tämän esimerkin avulla saat robotin reagoimaan infrapunapalloon. Kyseisen esimerkin avulla näet minkälaisia sektorikohtaisia arvoja anturi antaa milloinkin.
#pragma config(Sensor, S1, HTIRS2, sensorI2CCustom) #include "drivers/HTIRS2-driver.h" // download and include drivers // main task task main () { int _dirDC = 0; int _dirAC = 0; int dcS1, dcS2, dcS3, dcS4, dcS5 = 0; int acS1, acS2, acS3, acS4, acS5 = 0; for (int i = 0; i < 8; ++i) while (true) { // Read the current non modulated signal direction _dirDC = HTIRS2readDCDir(HTIRS2); if (_dirDC < 0) break; // I2C read error occurred // read the current modulated signal direction _dirAC = HTIRS2readACDir(HTIRS2); if (_dirAC < 0) break; // I2C read error occurred // Read the individual signal strengths of the internal sensors // Do this for both unmodulated (DC) and modulated signals (AC) if (!HTIRS2readAllDCStrength(HTIRS2, dcS1, dcS2, dcS3, dcS4, dcS5)) break; // I2C read error occurred if (!HTIRS2readAllACStrength(HTIRS2, acS1, acS2, acS3, acS4, acS5 )) break; // I2C read error occurred } }