Home / Experiments / Disco Inferno

Disco Inferno

Sometimes an idea comes into existence and you wonder why the heck nobody else came up with it. My good friend Laurens Valk was working on a robot for one of his classes and asked me if there was a way to PWM the pins on the sensor port, dig0 and dig1. He needed to control a non-NXT motor without using the motor ports. I suggested he tried configuring S4 as an RS485 port and send 0xFF and a bunch of 0x00’s.  The data pin would effectively become a pulse followed by a variable length of nothing, pretty much what PWM is.

Turns out it worked, too.

Anyway, I modified it a bit and made it into a little sound sensitive light. It looks kind of cool but I am sure someone out there will come up with a much greater application for this.  If you do, let me know, I’d love to hear about it!

The code is really quite simple.  I’ve pasted it below for your convenience.

#pragma config(Sensor, S1, SOUND, sensorSoundDBA)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
  ubyte nData[100];
  memset(nData, 0, sizeof(nData));
  nData[0] = 0xFF;

  //Set port 4 as a High Speed communication port
  nxtHS_Mode = hsRawMode;
  nxtEnableHSPort();
  nxtSetHSBaudRate(921600);

  while(true) {
    nxtWriteRawHS(nData[0], SensorValue[SOUND], 0);
    while(nxtHS_Status == HS_SENDING) EndTimeSlice();
  }
}

About Xander

Xander Soldaat is a Software Engineer and former Infrastructure Architect. He loves building and programming robots. He recently had the opportunity to turn his robotics hobby into his profession and has started working for Robomatter, the makers of ROBOTC and Robot Virtual Words.