Hi everyone I´m new to Arduino but not to Spektrum RCtransmitters and receivers and MrRCSound V4.1 soundboards for RCaireoplanes that has 4 inputs and 4 sounds out.
1 Throttle
2 MachineGuns with synchronous LEDs
3 Whistle
4 Guns
The transmitter has levers (turn knobs)on left and right side of the Tx, Llv and Rlv
Nick Poole wrote this code that should work just fine but would need more channels than I have!
/*
RC PulseIn Joystick
By: Nick Poole
SparkFun Electronics
Date: 5
License: CC-BY SA 3.0 - Creative commons share-alike 3.0
use this code however you'd like, just keep this license and
attribute. Let me know if you make hugely, awesome, great changes.
*/
int THR; // Here's where we'll keep our channel values from RX
int AUX2;
int AUX4;
int Whistle;// P-51 Whistle Servo 3 V4.1
int MG;// Machineguns connected to LEDout Servo 2 V4.1
int Guns;// Guns no LED Servo 4 V4.1
int Canopy;// Canopyservo
int Whistle = 3; //Throttle near max to activate P-51 whistle Servo 3
int MG = 11; //Machine guns on Servo 2 activates synchronous LED (outer pins)
int Guns = 12; //Gunsound without LED Servo 4
int Canopy = 13; //Turnknob opening (if avaiable) of canopy
void setup() {
pinMode(5, INPUT); // Set our input pins as such
pinMode(6, INPUT);
pinMode(7, INPUT);
Serial.begin(9600); // Pour a bowl of Serial
pinMode(Whistle, OUTPUT); //Set control pins to be outputs
pinMode(MG, OUTPUT);
pinMode(Guns, OUTPUT);
pinMode(Canopy, OUTPUT);
}
void loop() {
THR = pulseIn(5, HIGH, 25000); // Read the pulse width of
AUX2 = pulseIn(6, HIGH, 25000); // each channel
AUX4 = pulseIn(7, HIGH, 25000);
if (THR > 1500) {
Serial.println("Whistle: Engaged");
}
if (THR < 1500) {
Serial.println("Whistle: Disengaged");
}
/* I found that Ch1 was my left switch and that it
floats around 900 in the off position and jumps to
around 1100 in the on position */
Serial.print("LLv:"); // AUX2 was LLv
Serial.println(map(AUX2, 1000, 2000, -500, 500)); // center at 0
Serial.print("RLv:"); // AUX4 was RLv
Serial.println(map(AUX4, 1000, 2000, -500, 500)); // center at 0
Serial.println(); //make some room
delay(100);// I put this here just to make the terminal
// window happier
}
My goal is
1 Throttle high should activate Whistlepinout as in code, but propably closer to endpoint, aprox 1800-1900, throttle near max.
2 Aux channel 1 on Llv midpostition everything inactivated
Counterclockwise turn (<1500) sets MGoutpin HIGH with LEDs flashing
Clockwise turn (>1500)sets Gunpin HIGH, also would like to have a synchronous LED flashing on this channel, I have used this code that works, but need it to be activated for ca 2 sek as the Gunsound bursts aprox 2 sek See code at the end.
3 Aux channel 2 on Rlv midpostition everything inactivated
Counterclockwise turn (<1500) sets Whistlepinout HIGH with LEDs flashing (sometimes I want Whistle with lower throttle manually activated)
Clockwise turn (>1500) turns a canopy servo from closed to open position.
Gun LED flash
/*
Blink
Turns on an LED on for 30ms, then off for 50ms, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
This example code is in the public domain.
modified 8 May 2014
by Scott Fitzgerald
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(30); // wait for 30ms
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for 50ms
}
These are my first struggling steps towards writing code myself, I understand the syntax theoretically, but to write it seems a bit harder.
Best regards and hoping for the best.
Merry X-mas
Lasse Hellsten