Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I'm trying to write a code for the ICP DATA SWITCH using a analog joystick. Bear in mind that I haven't been coding for a long time when you read the code. :megalol:

 

Anyways, the problem is that when I use the "UP" and "SEQ" values, the switch ingame don't return to zero, unlike when I use "RET" and "DOWN".

Any suggestions on the code to fix this?

 

#define DCSBIOS_IRQ_SERIAL

 

#include "DcsBios.h"

 

 

int joyPin1 = A0; // slider variable connecetd to analog pin 0

int joyPin2 = A1; // slider variable connecetd to analog pin 1

int value1 = 0; // variable to read the value from the analog pin 0

int value2 = 0; // variable to read the value from the analog pin 1

int UP1 = 13;

int UP2 = 5;

int DOWN1 = 12;

int DOWN2 = 4;

int SEQ1 = 11;

int SEQ2 = 3;

int RET1 = 10;

int RET2 = 2;

 

DcsBios::Switch2Pos icpDataDnSw("ICP_DATA_DN_SW", 4);

DcsBios::Switch2Pos icpDataRtnSw("ICP_DATA_RTN_SW", 2);

DcsBios::Switch2Pos icpDataSeqSw("ICP_DATA_SEQ_SW", 3);

DcsBios::Switch2Pos icpDataUpSw("ICP_DATA_UP_SW", 5);

 

void setup() {

DcsBios::setup();

pinMode(UP1, OUTPUT);

pinMode(DOWN1, OUTPUT);

pinMode(SEQ1, OUTPUT);

pinMode(RET1, OUTPUT);

pinMode(UP2, INPUT);

pinMode(DOWN2, INPUT);

pinMode(SEQ2, INPUT);

pinMode(RET2, INPUT);

}

 

void loop() {

value1 = 0;

value2 = 0;

DcsBios::loop();

// reads the value of the variable resistor

value1 = analogRead(joyPin1);

// this small pause is needed between reading

// analog pins, otherwise we get the same value twice

delay(25);

// reads the value of the variable resistor

value2 = analogRead(joyPin2);

if(550 < value1 > 450){

digitalWrite(UP1, LOW);

digitalWrite(DOWN1, LOW);

}

if(550 < value2 > 450){

digitalWrite(SEQ1, LOW);

digitalWrite(RET1, LOW);

}

if(value1 >= 550) {

digitalWrite(UP1, HIGH);

}

else{

digitalWrite(UP1, LOW);

}

if(value1 <= 450) {

digitalWrite(DOWN1, HIGH);

}

else{

digitalWrite(DOWN1, LOW);

}

if(value2 >= 550) {

digitalWrite(SEQ1, HIGH);

}

else{

digitalWrite(SEQ1, LOW);

}

if(value2 <= 450) {

digitalWrite(RET1, HIGH);

}

else{

digitalWrite(RET1, LOW);

}

}

Edited by Lentaro
  • Recently Browsing   0 members

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