Programming help

I saw a code within the forum for navigational light setup for an RC plane and found the code to be very nice. I would like to make some changes but with me being new I feel lost at times with some of the more involved codes. I have been coping sketches and making small changes to learn how it works but I am stumped on the one I would like to modify! Is this the correct part of the forum for help? Dave

Maybe you could post a link to the org. sketch and describe in more detail what the problem is

Will do later today, at work for now. Thank you
Dave

I placed some notes where I would like to make some changes. I would like to add 2 more outputs one just duplicates a current code and the other one works opposite of the other. I would like to double flash one wing tip and then double flash the other and repeat. Dave

const int redled=3;
const int whiteled=5;  
const int twinred=6;   //would like to duplicate this output so its flash is opposite from the other. Flash, flash and during its low state the other output will flash, flash
const int revolving=9;  //would like to duplicate this output and control its timing

unsigned long previousred=0;
unsigned long previouswhite=0;
unsigned long revolvingtime=0;

int redoff=1000;
int redon=30;
int whiteoff=1100;
int whiteon=100;
int twinLongOff=1000;
int twinOn=40;
int twinOff=100;
int revolvingperiode=2000;
int value;
int FadeOff=2;
int FadeOn=2000;
unsigned long twinStartMillis=0;
unsigned long fadeStartMillis=0;

enum ledState {
  firstOnPeriod, shortInterval, secondOnPeriod, longInterval};
static ledState twinState=longInterval;

enum revolvingState {
  Fade, Off    };     
static revolvingState revolveState=Off;

void setup(){
  pinMode(redled, OUTPUT);
  pinMode(whiteled, OUTPUT);
  pinMode(twinred, OUTPUT);
}

void loop(){
  unsigned long currentred=millis();     
  unsigned long currentwhite=millis();
  if(currentred-previousred>=redon){    
    digitalWrite(redled, LOW);
  }
  if(currentred-previousred>=redoff){
    previousred=currentred; 
    digitalWrite(redled, HIGH);
  }
  if(currentwhite-previouswhite>=whiteon){  
    digitalWrite(whiteled, LOW);
  }
  if(currentwhite-previouswhite>=whiteoff){
    previouswhite=currentwhite;
    digitalWrite(whiteled, HIGH);
  }
  unsigned long now=millis();
  switch (twinState){                 
  


 case firstOnPeriod:                 
    if(now-twinStartMillis>=twinOn){
      digitalWrite(twinred,LOW);
      twinState=shortInterval;
    }
    break;
  case shortInterval:                
    if(now-twinStartMillis>=twinOn+twinOff){
      digitalWrite(twinred,HIGH);
      twinState=secondOnPeriod;
    }
    break;
  case secondOnPeriod:              
    if(now-twinStartMillis>=twinOn+twinOff+twinOn){
      digitalWrite(twinred,LOW);
      twinState=longInterval;
    }
    break;
  case longInterval:             
    if (now-twinStartMillis>=twinOn+twinOff+twinOn+twinLongOff){
      digitalWrite(twinred,HIGH);
      twinState=firstOnPeriod;
      twinStartMillis=now;
    }
    break;
  }
  switch (revolveState){           
  case Fade:
    if (now-fadeStartMillis >= FadeOn)
    {
      revolveState=Off;
      digitalWrite(revolving, LOW);
    }
    else
    {
      revolvingtime = now - fadeStartMillis;
      value = 128 - 128*cos((2*PI*(float)revolvingtime)/revolvingperiode);
      analogWrite(revolving, value);
    }
    break;
  case Off: 
    if (now-fadeStartMillis > FadeOn + FadeOff)
    {  
       revolveState=Fade;
       fadeStartMillis=now;
    }
    break;
  }

}

Just wanted to bump it up to see if anyone can help me here? Thanks Dave

cougar69:
Just wanted to bump it up to see if anyone can help me here?
Thanks
Dave

Your last post didn’t have a question.

What do you actually want to do, the code you posted is a bit messy and not really worth adapting, it would be better to start from scratch, but you need to provide a better description.

I had placed the question/changes within the sketch on lines 3 and 4 but I like the way the program works now just wanted to tweak it a little…
2 outputs setup for a single flash (control both high and low states independently)
2 outputs to simulated beacons to fade up and down (control both rates independently)
2 outputs to flash twice, one output would double flash and then the other output would flash twice (control both high and low along with the time between flashes and the 2 strobing outputs) i.e. (output 1) flash,flash,delay, (output 2) flash,flash,delay (repeat)

Sorry, I wish I had more time under my belt with Arduino code. I have only nicked the surface in the world of Arduino!
Dave

You've already got a state machine so most of the complexity has already been dealt with.

The ideal solution IMO would be to move your existing control logic into a class and instantiate as many of them as you need to control your different flash patterns.

After many (hate to say)hours of playing, I have it sketch where I want it. Im sure it can be cleaned up but for now, it works. Learned a lot during while adding and changing where I am happy! Dave