Jump to content

Recommended Posts

Posted

I was wondering if someone could look at my code I'm new at this.  I have a 3 position JFS Switch that is wired to an arduino board.  Then I have a 12v magnet powered by a MOSFET board that is getting a signal from the Arduino board based on the JFS Switch position.  Ok so I'm able to get the switch to magnetically release when the JFS Run light goes out but I can't get the switch to hold unless I delete the JFS Run Light code.  Can someone help me find out where I messed up in the code so that when I flip the switch to either JFS start 1 or 2 I get a signal to the MOSFET for the magnetic to get power and then release the magnetic when the run light goes out.  Thanks!

 

/*
  Tell DCS-BIOS to use a serial connection and use interrupt-driven
  communication. The main program will be interrupted to prioritize
  processing incoming data.
  
  This should work on any Arduino that has an ATMega328 controller
  (Uno, Pro Mini, many others).
 */
#define DCSBIOS_IRQ_SERIAL

#include "DcsBios.h"

int JfsSwChange_Coil = 2;    // Mag
int JfsSwChange_Coils = 2;

DcsBios::Switch3Pos jfsSw("JFS_SW", 3, 4);


// JFS Switch
void onJfsSwChange(unsigned int newValue) {
    switch (newValue){
      case 0:
      digitalWrite(JfsSwChange_Coil, HIGH);
      break;
      case 1:
      digitalWrite(JfsSwChange_Coil, LOW);
      break;
      case 2:
      digitalWrite(JfsSwChange_Coil, HIGH);
      break;
    }
}
DcsBios::IntegerBuffer jfsSwBuffer(0x4424, 0x0003, 0, onJfsSwChange);

//JFS Run Light
void onLightJfsRunChange(unsigned int newValue) {
    switch (newValue){
      case 0:
      digitalWrite(JfsSwChange_Coils, LOW);
      break;
      case 1:
      digitalWrite(JfsSwChange_Coils, HIGH);
      break;
    }
}
DcsBios::IntegerBuffer lightJfsRunBuffer(0x447c, 0x0020, 5, onLightJfsRunChange);

void setup() {
  DcsBios::setup();
  pinMode (JfsSwChange_Coil, OUTPUT);
  pinMode (JfsSwChange_Coils, OUTPUT);
}

void loop() {
  DcsBios::loop();
}

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...