Appendix C. Code Listings

Arranged by chapter, here are the complete listings of the NXC programs. You can also download them from the book website, in the Source Code/Download area at

Example C.1. blinkall.nxc

#define I2Cport S1       // Port number
#define I2CAddr8574 0x70 // I2C address x040 8574 or 0x70 for 8574A
byte WriteBuf[]={I2CAddr8574,0x00}; // write buffer is addr and data

task main() {
  int nbytes;
  SetSensorLowspeed (I2Cport);       // Configure I2C port
  while (true) {
    WriteBuf[1]++;                   // update data byte
    I2CWrite(I2Cport, 0, WriteBuf);  // send buffer
    while(I2CStatus(I2Cport, nbytes)==STAT_COMM_PENDING); // wait

Example C.2. low2high.nxc

#define I2Cport S1 // NXT sensor port 1 #define I2CAddr8574 0x40 // 0x40 8574 ...

Get Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.