Hi there
Struggling to get some code working and hoping someone can shed a light on what I'm doing wrong. This is for an active fan setup and if I can get this to work I will move on to a mapped range to take the airspeed and match to pwm fan speed. Canopy open, fans on - Eject, fans on FULL. Im VR only and need fans running for the first few minutes to combat the condensing on the lenses, so it might as well do something useful as well.
At the moment i just want the Monster Moto board on my Arduino uno to switch direction when the Canopy light status changes.
DCS Bios appears to be working as pushing the fire extinguisher in the A10c2 triggers the onboard LED (pin 13) perfectly and BORT also shows the canopy light status changing value from 0 to 1.
The boards work perfectly as I have a similar sketch I can upload to them that inputs values from an ir remote.
Normally I would watch the values change in the Serial Monitor, but thats a no go as its being used by DCS.
I just want to pass the newValue (0 or 1) from onCanopyunlockedChange to the Global usMotor_status which gets passed off to the MotorGo section.
I have tried for quite some time over the last week and got no result.
Thanks so much for your time!
DCS Bios Version 0.7.50
#define DCSBIOS_IRQ_SERIAL
#define BRAKE 0
#define CW 1
#define CCW 2
#define CS_THRESHOLD 15 // Definition of safety current (Check: "1.3 Monster Shield Example").
//MOTOR 1
#define MOTOR_A1_PIN 7
#define MOTOR_B1_PIN 8
//MOTOR 2
#define MOTOR_A2_PIN 4
#define MOTOR_B2_PIN 9
#define PWM_MOTOR_1 5
#define PWM_MOTOR_2 6
#define MOTOR_1 0
#define MOTOR_2 1
#include "DcsBios.h"
int pwm = 0;
short usSpeed = 0;
unsigned short usMotor_Status = CW;
DcsBios::LED masterCaution(0x1012, 0x0800, 13);
void onCanopyUnlockedChange(unsigned int newValue) {
if (newValue = 0) {
usMotor_Status = CCW;
} else if (newValue = 1) {
usMotor_Status = CW;
}
}
DcsBios::IntegerBuffer canopyUnlockedBuffer(0x10da, 0x0004, 2, onCanopyUnlockedChange);
void setup() {
DcsBios::setup();
pinMode(MOTOR_A1_PIN, OUTPUT);
pinMode(MOTOR_B1_PIN, OUTPUT);
pinMode(MOTOR_A2_PIN, OUTPUT);
pinMode(MOTOR_B2_PIN, OUTPUT);
pinMode(PWM_MOTOR_1, OUTPUT);
pinMode(PWM_MOTOR_2, OUTPUT);
}
void loop() {
motorGo(MOTOR_1, usMotor_Status, usSpeed);
motorGo(MOTOR_2, usMotor_Status, usSpeed);
DcsBios::loop();
}
void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm) //Function that controls the variables: motor(0 ou 1), direction (cw ou ccw) e pwm (entra 0 e 255);
{
if (motor == MOTOR_1) {
if (direct == CW) {
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, HIGH);
} else if (direct == CCW) {
digitalWrite(MOTOR_A1_PIN, HIGH);
digitalWrite(MOTOR_B1_PIN, LOW);
} else {
digitalWrite(MOTOR_A1_PIN, LOW);
digitalWrite(MOTOR_B1_PIN, LOW);
}
analogWrite(PWM_MOTOR_1, pwm);
} else if (motor == MOTOR_2) {
if (direct == CW) {
digitalWrite(MOTOR_A2_PIN, LOW);
digitalWrite(MOTOR_B2_PIN, HIGH);
} else if (direct == CCW) {
digitalWrite(MOTOR_A2_PIN, HIGH);
digitalWrite(MOTOR_B2_PIN, LOW);
} else {
digitalWrite(MOTOR_A2_PIN, LOW);
digitalWrite(MOTOR_B2_PIN, LOW);
}
analogWrite(PWM_MOTOR_2, pwm);
}
}