/************************************************************************/ /* */ /* Program Name: NRLink-Send-One-Byte-to-RCX-Example.c */ /* =========================== */ /* */ /* Copyright (c) 2008 by mindsensors.com */ /* Email: info () mindsensors () com */ /* */ /* This program is free software. You can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; version 3 of the License. */ /* Read the license at: http://www.gnu.org/licenses/gpl.txt */ /* */ /************************************************************************/ #include "NRLink-lib.c" const tSensors NRLinkPort = S1; // Connect NRLink sensor to this port!! const ubyte NRLinkID = 0x02; task main() { nI2CBytesReady[NRLinkPort] = 0; SensorType[NRLinkPort] = sensorI2CCustom9V; NRLinkSendCommand(NRLinkPort, NRLinkID, NRLinkFlush); NRLinkSendCommand(NRLinkPort, NRLinkID, NRLinkDefault); NRLinkSendCommand(NRLinkPort, NRLinkID, 'X'); // required when you are talking to RCX NRLinkWriteMacroByte(NRLinkPort, NRLinkID, 0x80, 0x02); NRLinkWriteMacroByte(NRLinkPort, NRLinkID, 0x81, 0xf7); //OP code for set message as by the remote control. NRLinkWriteMacroByte(NRLinkPort, NRLinkID, 0x82, 112); //Message ( value of 112 in this case). NRLinkWriteMacroByte(NRLinkPort, NRLinkID, 0x83, 0x02); NRLinkWriteMacroByte(NRLinkPort, NRLinkID, 0x84, 0xe1); //OP code for motor speed. NRLinkWriteMacroByte(NRLinkPort, NRLinkID, 0x85, 0x04); //data for this opcode while(true) { NRLinkRunMacro(NRLinkPort, NRLinkID, 0x80); // run the macro. wait1Msec(1000); NRLinkRunMacro(NRLinkPort, NRLinkID, 0x83); // run the macro. wait1Msec(1000); } } /* RCX Opcode refernce: http://graphics.stanford.edu/~kekoa/rcx/opcodes.html */