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.
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.
@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...".
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