Truck warning lights

Apologies. I think I put this in wrong section. Just now realized. But can't figure out delete. So can delete if it's in wrong section. Sorry.

Hey folks. Very new to arduino. I've spent hours searching trying tinting solution. It may have been covered and I'm just searching for wrong thing. I started out with a simple project to make a simple strobe light system for grill. After some searching and trying I eventually got them to do what I wanted. However, me being me, I want to go further. However I'm starting to think this may be beyond my lil arduino uno. Basically what I want is to be able to turn on or off 3 different "groups" of lights. I can write the loop to make each do what I want on their own. But I'm struggling to find a way to make 1 arduino control all 3. With 3 separate on/off switches. Is this possible or am I going to need to keep each set on their own controller?

For example, if maybe makes it easier to understand. Group 1:,have 3 outputs for the cab marker lights. Group 2: 2 outputs for LED pods in grill and rear. Group 3: 2 outputs for LED in each reverse light.

Each has a strobe pattern which is basically the same for each one. Except group 1 which has an extra output that goes constant. I want to be able to turn each group on or off independently by switches on dash. Example. Groups 1 and 3. Or just group 2. Etc etc.

Is this possible?

Hope so but if need be ill just use 3 arduino or maybe make a circuit with 3 chips.

Thanks. :Nick:

As long as you have enough inputs & outputs you can do it with one microcontroller.

It's seems like just a matter of some [u]if-statements[/u] and maybe some loops. i.e. If switch1 is on, activate the front lights. Otherwise turn them off, etc.

Take a look at the post at the top of the screen about Demonstration code for several things at the same time.

Your code will probably be "cleaner" if you can avoid delay (Look at the Blink Without Delay example).

You can probably do it with delay() but it will be trickier and it may not respond to your switches until the main loop and all of the delays are completed.

I saw that thread after I posted. I was frustrated and guess missed it.
I have reduced delays in my loop. this is the sketch for just the loop. it doesn’t include buttons etc. that is a mess right now and I need to clean it up. I can barely read it now.
each group is essentially the same, except for the LEDcircuit3. that was just to make 5 lights flash evenly by making the middle flash constant.

int LEDcircuit1=2; //set pin position of LED Circuits
int LEDcircuit2=3;
int LEDcircuit3=4;
int LEDcircuit4=5;
int LEDcircuit5=6;
int LEDcircuit6=7;
int LEDcircuit7=8;
int time1=50;  //set time between each flash
int time2=50;
int freq1=3;  //number of flashes per sequence
int freq2=3;


void setup() {
  pinMode(LEDcircuit1, OUTPUT);  //set pin mode for each circuit
  pinMode(LEDcircuit2, OUTPUT);
  pinMode(LEDcircuit3, OUTPUT);
 // pinMode(LEDcircuit4, OUTPUT);
 // pinMode(LEDcircuit5, OUTPUT);
 // pinMode(LEDcircuit6, OUTPUT);
 // pinMode(LEDcircuit7, OUTPUT);
}
 void loop() {
  
  
  for (int counter=0; counter<freq1; counter = counter+1) {  //start first bank flashing
    digitalWrite(LEDcircuit1, HIGH);
    digitalWrite(LEDcircuit3, HIGH);  //circuit3 flashing regardless of count
    delay(time1);
    digitalWrite(LEDcircuit1, LOW);
    digitalWrite(LEDcircuit3, LOW);
    delay(time1); } 
  
   for (int counter1=0; counter1<freq2; counter1 = counter1+1) {  //if count met, start second bank flashing
     digitalWrite(LEDcircuit2, HIGH);
     digitalWrite(LEDcircuit3, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit2, LOW);
    digitalWrite(LEDcircuit3, LOW);
    delay(time1); }}

I’ll keep playing with the IF statements. that’s the route I have been taking. just its doing everything but what I want it to.
long as I know it is possible and I’m not chasing the impossible, I’ll keep at it.
thanks

finally got a working code.
I think I took the scenic route though to a destination just down the road.
it’s a long way of doing it I’m sure, but this is all it has to do.
just swap out the LEDs for SSRs that will feed the various lights and I should be golden I hope.

/* this will control 3 warning strobe systems on a truck. including the roof marker lights, LED pods in the front and rear bumpers, and left and right reverse lights. */

const int LEDcircuit1=2; //set pin position of LED Circuits
const int LEDcircuit2=3;
const int LEDcircuit3=4;
const int LEDcircuit4=5;
const int LEDcircuit5=6;
const int LEDcircuit6=7;
const int LEDcircuit7=8;
const int Button1=9;
const int Button2=10;
const int Button3=11;
const int time1=50;  //set time between each flash
const int freq1=3;  //number of flashes per sequence
const int freq2=3;
int ButtonState1=0;
int ButtonState2=0;
int ButtonState3=0;


void setup() {
  pinMode(LEDcircuit1, OUTPUT);  //set pin mode for each circuit
  pinMode(LEDcircuit2, OUTPUT);
  pinMode(LEDcircuit3, OUTPUT);
  pinMode(LEDcircuit4, OUTPUT);
  pinMode(LEDcircuit5, OUTPUT);
  pinMode(LEDcircuit6, OUTPUT);
  pinMode(LEDcircuit7, OUTPUT);
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
  pinMode(Button3, INPUT);
}
 void loop() {
ButtonState1 = digitalRead(Button1);
ButtonState2 = digitalRead(Button2);
ButtonState3 = digitalRead(Button3);
  if (ButtonState1 == HIGH && ButtonState2 == LOW && ButtonState3 == HIGH) {
    grill(); }
   
  if (ButtonState1 == LOW && ButtonState2 == HIGH && ButtonState3 == HIGH) {
    marker_roof(); }

  if (ButtonState1 == LOW && ButtonState2 == LOW && ButtonState3 == HIGH) {
    marker_roof_grill(); }

  if (ButtonState1 == LOW && ButtonState2 == LOW && ButtonState3 == LOW) {
    full(); }

  if (ButtonState1 == HIGH && ButtonState2 == HIGH && ButtonState3 == LOW) {
    reverse(); }

  if (ButtonState1 == HIGH && ButtonState2 == LOW && ButtonState3 == LOW) {
    grill_reverse(); }

  if (ButtonState1 == LOW && ButtonState2 == HIGH && ButtonState3 == LOW) {
    marker_roof_reverse(); }
  }

 //routines       
  void marker_roof() {
  for (int counter=0; counter<freq1; counter = counter+1) {  //start first bank flashing
    digitalWrite(LEDcircuit1, HIGH);
    digitalWrite(LEDcircuit3, HIGH);  //circuit3 flashing regardless of count
    delay(time1);
    digitalWrite(LEDcircuit1, LOW);
    digitalWrite(LEDcircuit3, LOW);
    delay(time1); } 
  
   for (int counter1=0; counter1<freq2; counter1 = counter1+1) {  
     digitalWrite(LEDcircuit2, HIGH);
     digitalWrite(LEDcircuit3, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit2, LOW);
    digitalWrite(LEDcircuit3, LOW);
    delay(time1); }}

    void grill() {
      for (int counter2=0; counter2<freq1; counter2 = counter2+1) {  //start first bank flashing
    digitalWrite(LEDcircuit4, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit4, LOW);
    delay(time1); } 
  
   for (int counter3=0; counter3<freq2; counter3 = counter3+1) {  
     digitalWrite(LEDcircuit5, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit5, LOW);
    delay(time1); }}

    void marker_roof_grill() {
  for (int counter=0; counter<freq1; counter = counter+1) {  //start first bank flashing
    digitalWrite(LEDcircuit1, HIGH);
    digitalWrite(LEDcircuit3, HIGH);
    digitalWrite(LEDcircuit4, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit1, LOW);
    digitalWrite(LEDcircuit3, LOW);
    digitalWrite(LEDcircuit4, LOW);
    delay(time1); } 
  
   for (int counter1=0; counter1<freq2; counter1 = counter1+1) {  
     digitalWrite(LEDcircuit2, HIGH);
     digitalWrite(LEDcircuit3, HIGH);
     digitalWrite(LEDcircuit5, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit2, LOW);
    digitalWrite(LEDcircuit3, LOW);
    digitalWrite(LEDcircuit5, LOW);
    delay(time1); }}

    void reverse() {
     for (int counter2=0; counter2<freq1; counter2 = counter2+1) {  //start first bank flashing
    digitalWrite(LEDcircuit6, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit6, LOW);
    delay(time1); } 
  
   for (int counter3=0; counter3<freq2; counter3 = counter3+1) {  
     digitalWrite(LEDcircuit7, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit7, LOW);
    delay(time1); }}
    

    void full() {
  for (int counter=0; counter<freq1; counter = counter+1) {  //start first bank flashing
    digitalWrite(LEDcircuit1, HIGH);
    digitalWrite(LEDcircuit3, HIGH);
    digitalWrite(LEDcircuit4, HIGH);
    digitalWrite(LEDcircuit6, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit1, LOW);
    digitalWrite(LEDcircuit3, LOW);
    digitalWrite(LEDcircuit4, LOW);
    digitalWrite(LEDcircuit6, LOW);
    delay(time1); } 
  
   for (int counter1=0; counter1<freq2; counter1 = counter1+1) { 
     digitalWrite(LEDcircuit2, HIGH);
     digitalWrite(LEDcircuit3, HIGH);
     digitalWrite(LEDcircuit5, HIGH);
     digitalWrite(LEDcircuit7, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit2, LOW);
    digitalWrite(LEDcircuit3, LOW);
    digitalWrite(LEDcircuit5, LOW);
    digitalWrite(LEDcircuit7, LOW);
    delay(time1); }}

    void grill_reverse() {
  for (int counter=0; counter<freq1; counter = counter+1) {  //start first bank flashing
    digitalWrite(LEDcircuit4, HIGH);
    digitalWrite(LEDcircuit6, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit4, LOW);
    digitalWrite(LEDcircuit6, LOW);
    delay(time1); } 
  
   for (int counter1=0; counter1<freq2; counter1 = counter1+1) {  
     digitalWrite(LEDcircuit5, HIGH);
     digitalWrite(LEDcircuit7, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit5, LOW);
    digitalWrite(LEDcircuit7, LOW);
    delay(time1); }}

    void marker_roof_reverse() {
  for (int counter=0; counter<freq1; counter = counter+1) {  //start first bank flashing
    digitalWrite(LEDcircuit1, HIGH);
    digitalWrite(LEDcircuit3, HIGH);
    digitalWrite(LEDcircuit6, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit1, LOW);
    digitalWrite(LEDcircuit3, LOW);
    digitalWrite(LEDcircuit6, LOW);
    delay(time1); } 
  
   for (int counter1=0; counter1<freq2; counter1 = counter1+1) { 
     digitalWrite(LEDcircuit2, HIGH);
     digitalWrite(LEDcircuit3, HIGH);
     digitalWrite(LEDcircuit7, HIGH);
    delay(time1);
    digitalWrite(LEDcircuit2, LOW);
    digitalWrite(LEDcircuit3, LOW);
    digitalWrite(LEDcircuit7, LOW);
    delay(time1); }}

If I wanted to maybe get much more complicated, what would be a good method for eliminating the numerous if statements? since obviously that would get stupid as the number of instances increased.
is there a way? I’m not one who wants the code written for me, just pointed in right direction and left to figure it out.
everything I tried ended in frustration including a very well written tutorial using ‘object oriented way’ which I think is beyond my skill level at the moment. baby steps :slight_smile:

If you have a program that works the way you want. DON'T change it. Start over with a fresh program and make it do the same as your original program, only now, use what you have learned from the working program.

If you begin modifying the original program, you will never have anything to compare.

Paul

I'm inspired by you're determination, dont loose it.

Your if() statements are remarkably clean and easy to read. That is the best part of this program.

But have you tested it with more than one light group turned on at once? It will do the flashy-thing for one group, then that will stop while it flashes the other group.

Keep the main if() statement structure. That is great. But each function that controls a group should keep its own blink-without-delay timer, so it knows when each light is due to be turned on or off at any time. Think about the main loop running thousands of times per second, checking all those buttons and inputs. Then it calls each sub-function thousands of times per second. Those functions will look at the millis() clock and decide if this time is the time to change the state of a light.

The only wrinkle with using that if() structure and blink-without-delay is when you turn off a light group. Then it doesn't call that group's function and there's no opportunity for that function to gracefully turn off the lights.