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(); } }
Couldn’t you multiply the number of brightness levels by 8? You could control the number of active bits in the byte by adding values 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, and 0x80. Each one is a bit, or, theoretically, a pulse, and would have one pulse out of the set of eight. I was also wondering if you could create “white” by rapidly toggling all colors. I already tried making grayscale on the NXT screen, and although I’m not sure what values are “reasonable” yet, I know that displaying 100 pictures of a cat at different threshold values make a reasonable dimmer switch-like visual.
Why don’t you try it and let me know how it went? Like I said in my post, this is just to get people thinking on how they can improve on it.
[…] Xander Soldaat posted an article and video earlier today of a proof-of-concept that he’d come up with to show that you can send […]