Oh my lord back to this monster again. I took another look at what's really going on in this thing.

  • Display Switch
  • Mode Switch
  • Thumb Switch 1
  • Thumb Switch 2
  • int 1
  • int 2
  • int 3
  • int 4
  • Keyboard
  • int 5
  • Communications
  • int 0

I have broken it down into functional sections. By using the Arduino Mega I have  6 hardware interrupts 0 - 5, which will take care of the I/O.  Below you can see my logic for the hardware.

Basically by grounding the common of the switch which is the input to 8 to 3 priority encoder, which is normally pulled high. the encoder will output the code in binary. To make sure that my signal is clean I have employed an 8way NAND gate as well. The output signal of the gate is an input to a Schmitt trigger which is cleaned via an RC network shown below. Due to the limited amount of hardware interrupts I will have to do something called soft interrupts. basically all of the NAND gates go into an 8 to 3 priority encoder. The inputs also are wired to a NAND gate and Schmitt trigger when the Arduino sees the Interrupt line active it looks at 3 bits from the priority encoder.  This number from the priority encoder is the ISR that is then called. This may sound like a run-around but it does work, it is called 2 level interrupts.

void setup() {

// pins 2, 3 are not used

int DisplaySwitchINT = 18;

int ModeSwitchINT     = 19;

int ThumbSwitch1INT = 20;

int ThumbSwitch2INT = 21

int DisplaySwitchA  = 22;

int DisplaySwitchB  = 23;

int DisplaySwitchC  = 24;

int DisplaySwitchValue = 0;

int power_flag;

#define OFF 0

#define ON 1

// the reason why I have not specified the mode is I have to see it on my Oscope.

attachInterrupt(digitalPinToInterrupt(DisplaySwitchINT), getDisplaySwitch, mode); }

 

void loop() {

; }

 

// INERRUPT SERVICE

void getDisplaySwitch() {

     DisplaySwitchValue = 0;

      biteWrite( DisplaySwitchValue, 0, digitalRead( DisplaySwitchA ));

      biteWrite( DisplaySwitchValue, 1, digitalRead( DisplaySwitchB ));

      biteWrite( DisplaySwitchValue, 2, digitalRead( DisplaySwitchC ));

      switch( DisplaySwitchValue ) {

      case 0: { // Power OFF

          power_flag = OFF;

          break; }

      case 1: { // Lamp Test

          power_flag = ON;

          lamptest();

      break; }

          case 2: { // Test

          power_flag = ON;

      break; }

          case 3: { // UTM

      power_flag = ON;

          break; }

      case 4: { // LAT/LONG

          power_flag = ON;

      break; }

         case 5: { // BACKUP

         power_flag = ON;

      break;}

          default: { // should never get here!

      break; }}}