// NQC ( Not Quite C ) // PingPong.nqc // sensor #define ROTATION SENSOR_1 // motor #define MOTOR OUT_A #define KICK OUT_FWD #define BACK OUT_REV #define KICKSTOPFLOAT 73 #define KICKSTOPFULL 78 #define PLACEBALL 45 #define BACKSTOPFLOAT 10 #define BACKSTOPFULL 5 #define BALLS 3 sub init(){ SetSensor( ROTATION, SENSOR_ROTATION ); ClearSensor( ROTATION ); SetDirection( MOTOR, KICK ); Off( MOTOR ); } task main() { init(); int i = 1; while ( i <= BALLS ) { SetPower( MOTOR, 9 ); On( MOTOR ); while( ROTATION < KICKSTOPFLOAT ); Float( MOTOR ); while( ROTATION < KICKSTOPFULL ); Off( MOTOR ); Wait( 100 ); SetDirection( MOTOR, BACK ); On( MOTOR ); while( ROTATION > PLACEBALL ); PlaySound( SOUND_CLICK ); while( ROTATION > BACKSTOPFLOAT ); Float( MOTOR ); while( ROTATION > BACKSTOPFULL ); Off( MOTOR ); Wait( 100 ); SetPower( MOTOR, 1 ); if( ROTATION > 0 ) { On( MOTOR ); while( ROTATION > 0 ); } else { SetDirection( MOTOR, KICK ); On( MOTOR ); while( ROTATION < 0 ); } SetDirection( MOTOR, KICK ); Off( MOTOR ); i++; } }