It's out of control! lol.

I have a mostly working project, but the it's like the code won't stop after a single iteration and it seams to go through different processes.

3 buttons with 3 patterns to blink 3 leds.

Sometimes when I press button 2 it will do process 2, but then do process 1. Or it might just do process 2 until I reset the arduino. it feels like I have a lack of "stops" or debouce problems. this is the case for all of the buttons and programs(unfortunately) Thanks for the help :D!!

#include <Utility.h>
const int ledpinG = 9;
const int ledpinO = 10;
const int ledpinHERD = 11;
const int button1 = 4;
const int button2 = 3;
const int button3 = 5;
const byte ledpinsGO = 2;
int timer = 30;
byte ledPin[ledpinsGO] = {9,10};
int pulsewidth = 0;
int valGHG = 0;
int valGH = 0;
int valGOHERD = 0;

void setup()  {
  pinMode(ledpinG, OUTPUT);
  pinMode(ledpinO, OUTPUT);
  pinMode(ledpinHERD, OUTPUT);
  foreach(ledPin, ledpinsGO, pinMode, OUTPUT);
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  Serial.begin(9600);
}
  void loop()  {
    valGHG = digitalRead(button1);
    valGH = digitalRead(button2);
    valGOHERD = digitalRead(button3);
    
    if(valGHG ==HIGH)  {
 digitalWrite(ledpinG, HIGH);
 Serial.print("G");
 delay(timer);
 digitalWrite(ledpinG, LOW);
 delay(timer);
 
 digitalWrite(ledpinO, HIGH);
 Serial.print(" O");
 delay(timer);
 digitalWrite(ledpinO, LOW);
 delay(timer);
 
 digitalWrite(ledpinHERD, HIGH);
 Serial.print(" HERD");
 delay(timer);
 digitalWrite(ledpinHERD, LOW);
 delay(timer);
  Serial.print("\n\n\n\n");
 
 
    }
    if(valGH == HIGH)  {
      Serial.print("\nGO");
  digitalWrite(ledpinG, HIGH);
  digitalWrite(ledpinO,HIGH);
  delay(600);
  digitalWrite(ledpinG, LOW);
  digitalWrite(ledpinO,LOW);
  Serial.print("\nHERD");
  digitalWrite(ledpinHERD, HIGH);
  delay(600);
  digitalWrite(ledpinHERD, LOW);
  Serial.print("\nGO!!!");
   digitalWrite(ledpinG, HIGH);
   digitalWrite(ledpinO,HIGH);
  delay(400);
  digitalWrite(ledpinG, LOW);
  digitalWrite(ledpinO,LOW);
  delay(1000);
  Serial.print("\n\n\n\n");
}
if(valGOHERD == HIGH)  {
for (pulsewidth=0; pulsewidth<255; pulsewidth+=5){
   foreach(ledPin, ledpinsGO, analogWrite, pulsewidth);
   delay(50);
   Serial.print("\nGO");
 }

 foreach(ledPin, ledpinsGO, digitalWrite, HIGH);
 digitalWrite(ledpinHERD, HIGH);
  Serial.print("\nHERD!");
 delay(300);
 digitalWrite(ledpinHERD, LOW);
 delay(300);
  digitalWrite(ledpinHERD, HIGH);
  Serial.print("\nHERD!");
 delay(300);
 digitalWrite(ledpinHERD, LOW);
 delay(300);
  digitalWrite(ledpinHERD, HIGH);
  Serial.print("\nHERD!");
 delay(300);
 digitalWrite(ledpinHERD, LOW);
 delay(300);
 digitalWrite(ledpinHERD, HIGH);
  Serial.print("\nHERD!");
 delay(2000);
 digitalWrite(ledpinHERD, LOW);
 foreach(ledPin, ledpinsGO, digitalWrite, LOW);
 Serial.print("\n\n\n\n");


  }
      
  }

working_go_herd_v2.pde (2.32 KB)

3 buttons with 3 patterns to blink 3 leds.

These 3 buttons?

const int button1 = 4;
const int button2 = 3;
const int button3 = 5;

That you have properly defined as input:

  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);

But, you haven't enabled the pullup resistors, and you are comparing the values read to HIGH, leading me to presume, then, that you have external pull-down resistors wires with the switches. Is that true?

PaulS:

3 buttons with 3 patterns to blink 3 leds.

These 3 buttons?

const int button1 = 4;

const int button2 = 3;
const int button3 = 5;



That you have properly defined as input:


pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);



But, you haven't enabled the pullup resistors, and you are comparing the values read to HIGH, leading me to presume, then, that you have external pull-down resistors wires with the switches. Is that true?

You are so right. I don't know how I forgot that! lol. I was prototyping it before I completely reassembeled the project and I didn't include any pull downs :P. Thanks!

I didn't include any pull downs

You are much better off using a button connected to ground and enabling the internal pull ups.