OK, so I got it <almost> working now that I have this knowledge. I plugged the RC Recevier into the Netduino 5V (I got tired of the 4.8V battery back needing to be rechanged) and I added this code:
static OutputPort outputPort = new OutputPort(Pins.ONBOARD_LED, false); public static void Main() { InterruptPort inputPort = new InterruptPort(Pins.GPIO_PIN_D0, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); inputPort.OnInterrupt += new NativeEventHandler(inputPort_OnInterrupt); Thread.Sleep(Timeout.Infinite); } static long leadingEdge = 0; static long priorPulseWidth = 0; static void inputPort_OnInterrupt(uint data1, uint data2, DateTime time) { if (data2 == 1) { leadingEdge = time.Ticks; } else { long currentPulseWidth = (time.Ticks - leadingEdge) / 1000; long pulseWidthChange = currentPulseWidth-priorPulseWidth; if(pulseWidthChange > 0) { outputPort.Write(true); } if(pulseWidthChange < 0) { outputPort.Write(false); } priorPulseWidth = currentPulseWidth; } }
When I push the stick up, the LED lights (with an occasional flash depending if I stop when I am pulling it)
When I push and leave the stick motionless at max up, the LED flashes
When I pull the stick down, the LED truns off (with an occasional flash depending if I stop when I am pulling it)
When I pull the stcik down and leave the stick motionless at max down, the LED flashes.
I am thinking of doing an average to smooth out the noise when I am pulling and pushing the stick. I can't explain the max and min range blinking though...
- hanzibal likes this