Re: 1/16 Elefant Ludwig/Asiatam
Posted: Tue Sep 11, 2018 2:23 am
Code for engine sounds almost done. Got through the tough spot! 

RC Tank Warfare community modelling hobby forum
https://www.rctankwarfare.co.uk/forums/
Code: Select all
case 0:
bool maxrpm = 0
//in the loop
// so for case 0, track 12 is the max rpm sound wav (planned engine tracks to be 1-12)
// and accel 5 would be track 11 (or whatever, but in some ordered structure)
// etc.....
case 0:
Serial.print("MAX RPM");
digitalWrite(WAV2, HIGH); // not necessary, just for testing stick location w LED
if (maxrpm == 0) {
tsunami.trackLoop(12, 1);
tsunami.trackPlayPoly(12, 0, true);
maxrpm = 1; // allows only ONE loop play on the wav track even if stick held in same position
}
break;
case 1:
Serial.print("ACCEL5");
tsunami.trackStop(12);
if (maxrpm = = 1) {
maxrpm = 0; // this resets the bool to allow case 0 to trigger again
}
break;
Code: Select all
#include <Tsunami.h>
Tsunami tsunami;
//these are all the PWM pin inputs from the RMILEC sBus decoder
//pin #s do not necessarily correlate with RC Tx channels
//but kept in order from 1-16 w/RMILEC pin outs to Teensy pin in's
#define PWM1 2
#define PWM2 3 //engine throttle stick input
#define PWM3 4
#define PWM4 5
#define PWM5 6// CANFIRE
#define PWM6 7// MGFIRE
// none of these are necessary, just for testing
#define WAV1 14
#define WAV2 15//Engine rpm sounds
#define WAV3 16
#define WAV4 17
#define WAV5 18// CANFIRE
#define WAV6 19// MGFIRE
const int durationMin = 1000;
const int durationMax = 1950;
unsigned long duration;
unsigned long engineIdleTime;
unsigned long engineIdle = 5;
unsigned long MGFireTime;
unsigned long MGDelayTime = 250;
unsigned long reloadTime = 3000;
unsigned long startMillis;
unsigned long currentMillis;
bool runTimeA = 0;
bool runTimeB = 0;
bool runTimeC = 0;
bool runTimeD = 0;
bool runTimeE = 0;
bool runTimeF = 0;
bool runTimeG = 0;
bool runTimeH = 0;
bool runTimeI = 0;
void setup()
{
Serial.begin(57600);
tsunami.start();
delay(10);
tsunami.stopAllTracks();
startMillis = millis();
//each PWM channel is assigned to one pin input
//pin #s do not necessarily correlate with RC Tx channels
//but kept in order from 1-16 w/RMILEC pin outs
pinMode(PWM1, INPUT);
pinMode(PWM2, INPUT);
pinMode(PWM3, INPUT);
pinMode(PWM4, INPUT);
pinMode(PWM5, INPUT);
pinMode(PWM6, INPUT);
//none of these are necessary, just for testing
pinMode(WAV1, OUTPUT);
pinMode(WAV2, OUTPUT);
pinMode(WAV3, OUTPUT);
pinMode(WAV4, OUTPUT);
pinMode(WAV5, OUTPUT);
pinMode(WAV6, OUTPUT);
}
void loop() {
currentMillis = millis();
duration = pulseIn(PWM1, HIGH);
Serial.print ("PWM1 ");
Serial.print (duration);
digitalWrite(WAV2, LOW);
duration = pulseIn(PWM2, HIGH);
Serial.print ("\tPWM2 ");
int range = map(duration, durationMin, durationMax, 0, 8);
switch (range) {
case 0:
Serial.print("ACCEL4");
digitalWrite(WAV2, HIGH);
tsunami.trackStop(1);
tsunami.trackStop(2);
tsunami.trackStop(3);
tsunami.trackStop(10);
if (runTimeA == 0) {
tsunami.trackLoop(4, 1);
tsunami.trackPlayPoly(4, 0, true);
runTimeA = 1;
if (runTimeB == 1) {
runTimeB = 0;
}
}
break;
case 1:
Serial.print("ACCEL3");
tsunami.trackStop(4);
tsunami.trackStop(2);
if (runTimeB == 0) {
tsunami.trackLoop(3, 1);
tsunami.trackPlayPoly(3, 0, true);
runTimeB = 1;
if (runTimeA == 1) {
runTimeA = 0;
if (runTimeC == 1) {
runTimeC = 0;
}
}
}
break;
case 2:
Serial.print("ACCEL2");
tsunami.trackStop(3);
tsunami.trackStop(1);
if (runTimeC == 0) {
tsunami.trackLoop(2, 1);
tsunami.trackPlayPoly(2, 0, true);
runTimeC = 1;
if (runTimeB == 1) {
runTimeB = 0;
if (runTimeD == 1) {
runTimeD = 0;
}
}
}
break;
case 3:
Serial.print("ACCEL1");
tsunami.trackStop(2);
tsunami.trackStop(10);
if (runTimeD == 0) {
tsunami.trackLoop(1, 1);
tsunami.trackPlayPoly(1, 0, true);
runTimeD = 1;
if (runTimeC == 1) {
runTimeC = 0;
if (runTimeE == 1) {
runTimeE = 0;
}
}
}
break;
case 4:
Serial.print("IDLE");
tsunami.trackStop(1);
tsunami.trackStop(2);
tsunami.trackStop(3);
tsunami.trackStop(4);
if (runTimeE == 0) {
tsunami.trackLoop(10, 1);
tsunami.trackPlayPoly(10, 0, true);
runTimeE = 1;
if (runTimeD == 1) {
runTimeD = 0;
if (runTimeF == 1) {
runTimeF = 0;
}
}
}
break;
case 5:
Serial.print("ACCEL1");
tsunami.trackStop(10);
tsunami.trackStop(2);
if (runTimeF == 0) {
tsunami.trackLoop(1, 1);
tsunami.trackPlayPoly(1, 0, true);
runTimeF = 1;
if (runTimeE == 1) {
runTimeE = 0;
if (runTimeG == 1) {
runTimeG = 0;
}
}
}
break;
case 6:
Serial.print("ACCEL2");
tsunami.trackStop(1);
tsunami.trackStop(3);
if (runTimeG == 0) {
tsunami.trackLoop(2, 1);
tsunami.trackPlayPoly(2, 0, true);
runTimeG = 1;
if (runTimeF == 1) {
runTimeF = 0;
if (runTimeH == 1) {
runTimeH = 0;
}
}
}
break;
case 7:
Serial.print("ACCEL3");
tsunami.trackStop(2);
tsunami.trackStop(4);
if (runTimeH == 0) {
tsunami.trackLoop(3, 1);
tsunami.trackPlayPoly(3, 0, true);
runTimeH = 1;
if (runTimeG == 1) {
runTimeG = 0;
if (runTimeI == 1) {
runTimeI = 0;
}
}
}
break;
case 8:
Serial.print("ACCEL4");
tsunami.trackStop(1);
tsunami.trackStop(2);
tsunami.trackStop(3);
tsunami.trackStop(10);
if (runTimeI == 0) {
tsunami.trackLoop(4, 1);
tsunami.trackPlayPoly(4, 0, true);
runTimeI = 1;
if (runTimeH == 1) {
runTimeH = 0;
}
}
break;
}
duration = pulseIn(PWM3, HIGH);
Serial.print ("\tPWM3 ");
Serial.print (duration);
duration = pulseIn(PWM4, HIGH);
Serial.print ("\tPWM4 ");
Serial.print (duration);
duration = pulseIn(PWM5, HIGH);
Serial.print ("\tPWM5 ");
if (currentMillis - startMillis < reloadTime) {
Serial.print("RELOAD");
digitalWrite(WAV5, LOW);
}
else if (duration >= 1800) {
startMillis = currentMillis;
Serial.print("CANFIRE");
digitalWrite(WAV5, HIGH);
delay(5);
tsunami.trackPlayPoly(19, 0, true);
}
else if (duration <= 1799)
{
Serial.print(duration);
digitalWrite(WAV5, LOW);
}
duration = pulseIn(PWM6, HIGH);
Serial.print ("\tPWM6 ");
if (currentMillis - MGFireTime > MGDelayTime) {
tsunami.trackStop(20);
if (duration > 1800) {
MGFireTime = currentMillis;
tsunami.trackPlayPoly(20, 0, true);
tsunami.trackLoop(20, true);
digitalWrite(WAV6, HIGH);
Serial.println("MGFIRE");
}
}
else (duration < 1799);{
digitalWrite(WAV6, LOW);
Serial.println(duration);
}
}
Hi, where did you get the convoy light?xrad wrote:Thx Soeren. Here is convoy light in blue. 5mm LED heat shrink tube to aluminum tube holding the fiber. Luckily, it fit into body without hitting the subwoofer. The LED is plenty bright. I polished the inside ends of the fishing line w/1500 grit, but it was old poor quality line and not very reflective internally. But, I think it's scale brightness (in other words, dim).
I added some pics of the other convoy lights I made for other tanks on this site.