#pragma config(Sensor, S1, HTIRL, sensorI2CCustom)
#include "drivers/hitechnic-irlink.h"
void doPFcomboPwmModeTest(byte speed);
void doPFcomboDirectModeTest(byte speed);
void doPFsinglePinOutputModeTest(byte speed);
void stopMotors();
task main {
byte mode = 0;
byte speed = 0;
nxtDisplayCenteredTextLine(0, "HiTechnic");
nxtDisplayCenteredBigTextLine(1, "IRLink");
nxtDisplayCenteredTextLine(3, "Test 1");
nxtDisplayCenteredTextLine(5, "Connect sensor");
nxtDisplayCenteredTextLine(6, "to S1");
wait1Msec(2000);
eraseDisplay();
nxtDisplayCenteredTextLine(0, "IRLink Test 1");
nxtDisplayTextLine(3, "Press [ENTER]");
nxtDisplayTextLine(4, "to switch modes");
nxtDisplayTextLine(6, "Press < and >");
nxtDisplayTextLine(7, "to change speed");
while (true) {
if (nNxtButtonPressed == kLeftButton)
speed--;
else if (nNxtButtonPressed == kRightButton)
speed++;
else if (nNxtButtonPressed == kEnterButton) {
speed = 0;
stopMotors();
mode++;
if (mode > 2) mode = 0;
}
while (nNxtButtonPressed != kNoButton) EndTimeSlice();
if (speed < 0) speed = 0;
else if (speed > 15) speed = 15;
switch (mode) {
case 0: doPFcomboPwmModeTest(speed); break;
case 1: doPFcomboDirectModeTest(speed); break;
case 2: doPFsinglePinOutputModeTest(speed); break;
}
while (nNxtButtonPressed == kNoButton) EndTimeSlice();
}
}
void doPFcomboPwmModeTest(byte speed) {
nxtDisplayCenteredTextLine(1, "comboPWM %d", speed);
PFcomboPwmMode(HTIRL, 0, (ePWMMotorCommand)speed, (ePWMMotorCommand)(15 - speed));
}
void doPFcomboDirectModeTest(byte speed) {
if (speed > 3) speed = 3;
nxtDisplayCenteredTextLine(1, "comboDirect %d", speed);
PFcomboDirectMode(HTIRL, 0, (eCDMMotorCommand)speed, (eCDMMotorCommand)(3 - speed));
}
void doPFsinglePinOutputModeTest(byte speed) {
nxtDisplayCenteredTextLine(1, "PFMotor %d", speed);
PFMotor(pfmotor_S1_C1_A, (ePWMMotorCommand)speed);
PFMotor(pfmotor_S1_C1_B, (ePWMMotorCommand)(15 - speed));
}
void stopMotors() {
PFcomboDirectMode(HTIRL, 0, CDM_MOTOR_BRAKE, CDM_MOTOR_BRAKE);
}