Auto and up down

Good morning i am new with the arduino and i have a problem with this code

//Global Variables
const byte auto1 = 7; 
const byte LED = 13;
const byte LED1 = 11;
const byte LED2 = 12; 
const byte up = 5;
const byte down = 6; 



unsigned long buttonPushedMillis; // when button was released
unsigned long ledTurnedOnAt; // when led was turned on
unsigned long turnOnDelay = 10; // wait to turn on LED
unsigned long turnOffDelay = 5000; // turn off LED after this time
bool ledReady = false; // flag for when button is let go
bool ledState = false; // for LED is on or not.
int state2 = 0;
int state = 0;
int state1 = 0;
int state3 = 0;
int state4 = 0;
int state5 = 0;




void setup() {
  pinMode(auto1, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(up, INPUT);
  pinMode(down, INPUT);
  digitalWrite(LED, LOW);
  // Set input/output modes of pins
}





void loop() {


  state2 = digitalRead(auto1);
  if (state2 == LOW) {
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
  }

  else {

    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
    loop1();
    state2 = digitalRead(auto1);
    state1 = digitalRead(down);

    if ((state2 == HIGH) && (state1 == HIGH)) {
      loop2();
    }
    state4 = digitalRead(up);
    state2 = digitalRead(auto1);
    if ((state4 == HIGH) && (state3 == HIGH)) {
      loop3();
    }

  }


}








void loop1() {
  // get the time at the start of this loop()
  unsigned long currentMillis = millis();

  // check the button
  if (digitalRead(auto1) == LOW) {
    // update the time when button was pushed
    buttonPushedMillis = currentMillis;
    ledReady = true;
  }

  // make sure this code isn't checked until after button has been let go
  if (ledReady) {
    //this is typical millis code here:
    if ((unsigned long)(currentMillis - buttonPushedMillis) >= turnOnDelay) {
      // okay, enough time has passed since the button was let go.
      digitalWrite(LED, HIGH);
      // setup our next "state"
      ledState = true;
      // save when the LED turned on
      ledTurnedOnAt = currentMillis;
      // wait for next button press
      ledReady = false;
    }
  }

  // see if we are watching for the time to turn off LED
  if (ledState) {
    // okay, led on, check for now long
    if ((unsigned long)(currentMillis - ledTurnedOnAt) >= turnOffDelay) {
      ledState = false;
      digitalWrite(LED, LOW);
    }
  }
}

void loop2() {
  state1 = digitalRead(down);
  state3 = digitalRead(auto1);
  if ((state1 == HIGH) && (state2 == HIGH)) {
    digitalWrite(LED1, HIGH);
  }
  else {
    digitalWrite(LED1, LOW);
  }
}

void loop3() {
  state5 = digitalRead(up);
  state2 = digitalRead(auto1);
  if ((state5 == HIGH) && (state2 == HIGH)) {
    digitalWrite(LED, HIGH);
  }
  else {
    digitalWrite(LED, LOW);
  }
}

i have 3 buttons and 3 leds -1 up -2 down and- 3 auto when i press the auto the yellow and blue is HIGH thats what i want and when i press the auto again the up led is HIGH and close again and its going to manual up down but the manual is not working.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Hi, @UKHeliBob
Getting this:

Oops! That page doesn’t exist or is private.

here, for your link. But I can navigate to that forum page, so it's your link that's bad, I think.

1 Like
//Global Variables
const byte LED = 13;
const byte LED1 = 11;
const byte LED2 = 12;
const byte up = 5;
const byte down = 6;
const byte auto1 = 7;

unsigned long turnOffDelay = 5000; // turn off LED after this time

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(up, INPUT_PULLUP);
  pinMode(down, INPUT_PULLUP);
  pinMode(auto1, INPUT_PULLUP);
}

void loop() {
  static bool isAuto = false;

  if (digitalRead(auto1) == LOW && isAuto == false) {
    isAuto = true;
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, HIGH);
  }

  if (digitalRead(auto1)  && isAuto ) {
    isAuto = false;
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
    digitalWrite(LED, HIGH);
    delay(turnOffDelay);
    digitalWrite(LED, LOW);
  }
}

1 Like

@arduino_first Welcome to the Forum! You'll find lots of helpers here, but we're highly focussed on 'technical', which means we thrive on details, completeness, and clarity.

Highly suggest you go to the Category "programming Questions", and read the suggested "How to get...".

it didnt work when the up ligh turns off i wnat to use it manually

what manually? what should happen when you press up/down?

up LED =HIGH when i stop pressing the button LOW and down LED1=HIGH and when i stop pressing it LOW

up - led, down button change led1, what do led2?

led= up, led1=down,auto1=led2

//Global Variables
const byte LED = 13;
const byte LED1 = 11;
const byte LED2 = 12;
const byte up = 5;
const byte down = 6;
const byte auto1 = 7;

unsigned long turnOffDelay = 5000; // turn off LED after this time

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(up, INPUT_PULLUP);
  pinMode(down, INPUT_PULLUP);
  pinMode(auto1, INPUT_PULLUP);
}

void loop() {
  static bool isAuto = false;
  if (isAuto == false) {
    digitalWrite(LED, digitalRead(up) == LOW);
    digitalWrite(LED1, digitalRead(down) == LOW);
    if (digitalRead(auto1) == LOW ) {
      isAuto = true;
      digitalWrite(LED1, HIGH);
      digitalWrite(LED2, HIGH);
    }
  }
  if (digitalRead(auto1)  && isAuto ) {
    isAuto = false;
    digitalWrite(LED2, HIGH);
    delay(turnOffDelay);
    digitalWrite(LED2, LOW);
    digitalWrite(LED1, LOW);
    digitalWrite(LED, LOW);
  }
  delay(50);
}

Sorry for the delay it didnt work i will send you pictures but with my code installed the only thing is the up is not working




Blue is auto, down is yellow, and up is green ,blue and yellow must work together when you change it to manual the up is enabled and turns off after some time and then you can use the manual only the up manual is not working

Pictures like that are really a waste of time. It is difficult to see where all the connections to the board go, the polarity of the LEDs and the logical connection between the code and the mess of wiring

A schematic of the project, even it is hand drawn, would be much easier to follow, particularly if it is laid out as normal with the GND line at the bottom, 5v or 3.3V at the top and with all components and pin numbers clearly labelled

use easyeda.com

i will send it from glorious jofo and i will make it on easyda

because i cant upload pdf for now