I programmed my Arduino Mega 2560 for my Boeing 777 Overhead panel with this code:
- Arduino:
OHpanel.ino- FG protocol file:
ArduinoOHPanel.xml (put in your fgdata/protocol folder)
- FG nasal file that loads on startup:
Arduino.nas (put in your fgdata/nasal folder)
Then I start FlightGear with this line in the settings tab: --generic=serial,in,10,\com4,9600,ArduinoOHPanel
The panel is still very basic: I used cheap push buttons with a locking mechanism for the push buttons and put a green led next to them. The output of the push buttons is tied to both an Arduino input and the base of a transistor. That transistor is tied with the collector to one of the ledpwm outputs (see code) and to an LED with the emitter. This makes the corresponding LED of a button light up if the Led output commands so.
The brightness of the LED's depends on the state of the IND LTS switch: DIM gives a PWM of 50, BRT sets them high and TEST lets them blink.
If none of the electrical power switches is on (battery, APU Gen en Ext Pwr 1 and 2 implemented), then all the leds go dark. The OHpanel is still one way: none of the FlightGear systems communicate to it.
For the rotary switches, I used three way toggle switches (ON-OFF-ON) for now. They are way cheaper than rotary switches. Both ON positions are tied with a 6k-8k resistor and to an analog input on the Arduino. In that way I can read the three positions with one analog input on the Arduino instead of using 2 digital inputs. I've thought of reading the state of two switches with one analog input, which should be feasible with different resistors, but as I had enough inputs and the voltage was fluctuating too much with all the LED's, I decided to do it this way. When I find affordable rotary switches, I can simply replace the toggle switches.
Hope this helps you a bit. Let me know if you find a better way of doing stuff
edit: here is an image of my OHpanel.
image (too big for the forums)
edit 2:
I made a (not so) short video to demonstrate the OHpanel. Take a look
here.