I recently purchased a quadcopter and have an extra channel that is open on my tx/rx. I want to use this open channel to control a programmable switch with 8 channels that can be selected by toggling a single switch on my transmitter.
toggle 1 times: Channel 1 turns on
toggle 2 times: channel 2 comes on
.......
toggle 8 times: channel 8 comes on
toggle 1 time again: channel one now turns off
The receiver would basicly produce a logic high(5 Volts) when the switch is toggled, each channel can be individually turned on/off by counting the number of times the switch was toggled, and the channels should latch in/out - on/off.
The operation of the program is different than just an up/down counter in that each channel can be selected at random rather than going through the entire 8 channels until it overflows back to channel 1.
I tried contacting the producer of the video but have received no response, so I am here trying to reproduce the same project. I am not sure if this can be done with an mcu or how to program it.
Basically, you have a set of outputs. You need to be able to track the on/off state of each output.
Then, you have a piece of code that monitors the input from the receiver. It needs to debounce the input and be able to detect pulse transitions. As each pulse is detected, increment a counter. If a certain time has passed with no more pulses, then use that count to flip the state of the indicated output.
One thing to keep in mind is that the output from the RC receiver is likely not a single pulse. Odds are that it will be a pulse stream similar to the stream going to servos: a pulse that varies from about 1 to 2 ms or so, repeating about every 20 ms. When the switch is in one position, it will have one pulse width, and when in the other position it will have another. The code will likely have to keep reading pulses, and look for the changes in the pulse widths to trigger the counter.
This is a doable project, but probably not something that you should try as your first program. There are a lot of parts that have to work together, and when it doesn't work, it will be hard to figure out what's causing the problem. From your post, it sounds like you're new at this. If not, please accept my apologies.
I would start simple and build it in steps:
First, be able to turn a single LED on and off using commands from the serial port
Next, be able to individually control multiple LEDs on and off using commands from the serial port
Next, set the LED code aside and figure out how to hook up a switch so that when you press it, it prints a single message out the serial port, and when you release it, it prints a different single message. It's cheating if you have it constantly print messages as long as the button is pressed, that won't accomplish what you want. It's important that the button be "debounced"
Now, have the button presses increment a counter, and write the count out the serial port
Then, add a timeout so you can tell the end of a button press sequence, and print out a message saying how many button presses there were
Finally, you can combine this button counter code with the LED code: when you print out the button count message, also turn the indicated LED on or off.
With that working, set it all aside, and figure out how to count pulses from the receiver. First step is figure out if it's a steady stream of servo pulses, or if it really is a single pulse that tracks the switch position. If it's a stream of servo pulses, figure out how to determine the two states.
Finally, you can put it all together: take the pulses from the receiver (either directly or from the pulse detection code in the previous step, and use that to trigger the button press code, which sets the LED outputs
Thank you for the detailed step by step procedure to figuring out how to get things programmed and working together.
I have done a few projects with the Arduino Due, most recent was a 10 fan PWM speed controller based on voltage divider / thermocouple readings on the analog input ports, but have not tried to program something this complicated or using the serial ports.
This will take some time and patience as I learn something new.
BMcBride:
but have not tried to program something this complicated or using the serial ports.
Complicated? That's why you break it down into a series of small steps. Eating an elephant is easier when you concentrate on one bite byte at a time.
And for the serial port, you don't need anything fancy: just read a single digit and use that to select which output to toggle. Everything else is just print statements so you can see what's happening.
if (Serial.Available())
{
switch (Serial.read())
{
case '1':
toggleLED(1);
break;
case '2':
toggleLED(2);
break;
case '3':
toggleLED(3);
break;
// etc...
}
}