button does not work

hey i made this project and everything works fine , except the button the that should light up the led in pin 13 , that’s the only thing that does not work and i don’t know why.

please help, this is probably an easy problem.

the name of the button is

button

the button state of the button is

buttonState

and the if is on the line 107

Please post your code here inside code tags, so I don't have to follow an external link to see it. The forum instructions are in the sticky posts at the top of the list.

this is probably an easy problem.

It might be, but since you put your code in the rubbish bin, I'm forced to assume that that is appropriate.

Is your code so large that that was necessary? If so, shitcan most of it, posting only enough to illustrate the problem. That can't be more than 10 lines of code.

I think that you'll find it more effective to use switches with the Arduino, and leave the buttons for your shirts.

You absolutely must describe how the button is sewn on to the Arduino.

You only set/clear buttonstate in setup(),

buttonState = digitalRead(button);

but not in loop().

PaulS: You absolutely must describe how the button is sewn on to the Arduino.

Multi-threaded?

aarg: Multi-threaded?

Now that was funny.

CrossRoads: You only set/clear buttonstate in setup(),

buttonState = digitalRead(button);

but not in loop().

the buttonState is in setup not in loop

The message exceeds the maximum allowed length (9000 characters).

i can not post the code here sorry.

aarg:
Multi-threaded?

the button works. I changed the pins with other buttons that work and everything is fine with the wiring.

i can not post the code here sorry.

Why not? Use Reply, not the Quick Reply field, and attach the code, using the Additional Options link.

Ok i am just gonna divide the code in two.
since it is still over 9000 characters.

// when compiling for attiny erase serial print and change pin numbers
 
 
 
// relay pin
 
#define relay_PIN0 0 // 0
#define relay_PIN1 0
#define relay_PIN2 0
#define relay_PIN3 0
#define relay_PIN4 0
#define relay_PIN5 0
 
// for counting
 
int increasetempbutton = 3;  // switch is connected to pin 4
int va;// variable for reading the pin status
int buttonState2;                // variable to hold the button state
int buttonPresses = 0; // how many times the button has been pressed
int count;
 
int decreasetempbutton = 2;  // switch is connected to pin 4
int buttonState3;
int va2;// variable for reading the pin status
 
 
//button to make count go to zero
 
int button = 5;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status
 
 
 
 
// debouce
 
 
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers
 
// for the timing on and off
 
#define relay_ON1 1000       //milliseconds
#define relay_OFF1 10000
 
#define relay_ON2 1000       //milliseconds
#define relay_OFF2 5000
 
#define relay_ON3 2000       //milliseconds
#define relay_OFF3 3000
 
#define relay_ON4 2000       //milliseconds
#define relay_OFF4 2000
 
unsigned long ms1;        //time from millis()
unsigned long msLast1;    //last time the LED changed state
 
unsigned long ms2;        //time from millis()
unsigned long msLast2; //last time the LED changed state
 
unsigned long ms3;        //time from millis()
unsigned long msLast3;    //last time the LED changed state
 
unsigned long ms4;        //time from millis()
unsigned long msLast4;    //last time the LED changed state
 
 
 
boolean relayState1;        //current LED state
boolean relayState2;        //current LED state
boolean relayState3;  
boolean relayState4;        //current LED state
 
 
boolean replay0 = true; // to blink once
boolean replay1 = true; // to blink once
boolean replay2 = true; // to blink once
boolean replay3 = true; // to blink once
boolean replay4 = true; // to blink once
boolean replay5 = true; // to blink once
 
 
void setup(void)
{
    pinMode(relay_PIN0, OUTPUT);
    pinMode(relay_PIN1, OUTPUT);
    pinMode(relay_PIN2, OUTPUT);
    pinMode(relay_PIN3, OUTPUT);
    pinMode(relay_PIN4, OUTPUT);
    pinMode(relay_PIN5, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(button, INPUT);  
    pinMode(increasetempbutton, INPUT);
    pinMode(decreasetempbutton, INPUT);
    buttonState2 = digitalRead(increasetempbutton);   // read the initial state
    buttonState3 = digitalRead(decreasetempbutton);
    buttonState = digitalRead(button);
    Serial.begin(9600);
}
 
void loop(void)
{
     
       
 if (buttonState == HIGH) {
 
 
   
   digitalWrite(13, HIGH);
   
  }
 
     buttonState2 = va;
     buttonState3 = va2;
     count = buttonPresses;
     Serial.println(count);
     ms1 = millis();
     ms2 = millis();
     ms3 = millis();
     ms4 = millis();
   
   va = digitalRead(increasetempbutton);      
      if (va != buttonState2) {        
        if (va == LOW) {              
          buttonPresses++ ;              
        }
 
}
 
 
   
 
   va2 = digitalRead(decreasetempbutton);      
      if (va2 != buttonState3) {        
        if (va2 == LOW) {              
          buttonPresses-- ;              
        }
 
        }
 
 
 
 
       
    //blink code and count  this make the count go to 0 again  
       
     if (count > 5) {
       
         buttonPresses--;
         buttonPresses--;
         buttonPresses--;
         buttonPresses--;
         buttonPresses--;
         buttonPresses--;
      }
     
      if (count < 0 ) {
       
        buttonPresses++;
        buttonPresses++;
        buttonPresses++;
        buttonPresses++;
        buttonPresses++;
        buttonPresses++;
        }
 if (count == 0) {
   
        digitalWrite(relay_PIN0, LOW);
         if (replay0 == true) {
           
             replay0 = false;
             replay1 = true;
             replay5 = true;
       }
       }
 
   if (count == 1) {
   
   
    if (ms1 - msLast1 > (relayState1 ? relay_ON1 : relay_OFF1)) {
        digitalWrite(relay_PIN1, relayState1 = !relayState1);
        msLast1 = ms1; }
       
             if (replay1 == true) {        
               
               digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
               delay(150);              // wait for a second
               digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
               delay(150);
        replay1 = false;
         
       }
        replay2 = true;
        replay0 = true;
       }
   
 
 
     
   if (count == 2) {
    if (ms2 - msLast2 > (relayState2 ? relay_ON2 : relay_OFF2)) {
        digitalWrite(relay_PIN2, relayState2 = !relayState2);
        msLast2 = ms2; }
 
 if(replay2 == true){
 
        digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(150);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(150);
                digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(150);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(150);
           replay2 = false;
         }
          replay1 = true;
          replay3 = true;
         }
       
       
 
   if (count == 3) {
    if (ms3 - msLast3 > (relayState3 ? relay_ON3 : relay_OFF3)) {
        digitalWrite(relay_PIN3, relayState3 = !relayState3);
        msLast3 = ms3;
        }
  if(replay3 == true){
           
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(150);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(150);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(150);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(150);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(150);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(150);
            replay3 = false;
     }
      replay2 = true;
      replay4 = true;
     }
       
       
    if (count == 4) {
    if (ms4 - msLast4 > (relayState4 ? relay_ON4 : relay_OFF4)) {
        digitalWrite(relay_PIN4, relayState4 = !relayState4);
        msLast4 = ms4;
        }
          if (replay4 == true)
        {
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
 
         replay4 = false;
        }
         replay3 = true;
         replay5 = true;
        }
       
    if (count == 5) {
   
    digitalWrite(relay_PIN0, LOW);
   
      if(replay5 == true){
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
           digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
           delay(250);              // wait for a second
           digitalWrite(4, LOW);    // turn the LED off by making the voltage LOW
           delay(250);
         replay5 = false;
        }
         replay4 = true;
         replay0 = true;
        }
     
}

I don't think that you are taking notice of the replies here. This code

  buttonState = digitalRead(button);

is only in setup(), not loop() so once setup() is finished buttonState will not change. Is that what you mean the program to do ?

How is the button wired ?

#define relay_PIN0 0 // 0
#define relay_PIN1 0
#define relay_PIN2 0
#define relay_PIN3 0
#define relay_PIN4 0
#define relay_PIN5 0

What crap is this?Why do you have 6 names for 0?

boolean relayState1;        //current LED state
boolean relayState2;        //current LED state
boolean relayState3;  
boolean relayState4;        //current LED state

Either the comment is stupid or the variable name is.

When you start having to number variables, its past time to look into arrays.

UKHeliBob: I don't think that you are taking notice of the replies here. This code

  buttonState = digitalRead(button);

is only in setup(), not loop() so once setup() is finished buttonState will not change. Is that what you mean the program to do ?

How is the button wired ?

i put it in loop as well it works

thanks for the help ;)

PaulS: ```

define relay_PIN0 0 // 0

define relay_PIN1 0

define relay_PIN2 0

define relay_PIN3 0

define relay_PIN4 0

define relay_PIN5 0



What crap is this?Why do you have 6 names for 0?



boolean relayState1;        //current LED state boolean relayState2;        //current LED state boolean relayState3;  boolean relayState4;        //current LED state ```

Either the comment is stupid or the variable name is.

When you start having to number variables, its past time to look into arrays.

That's so i can blink an led without using delay and have various levels of delay.

That's so i can blink an led without using delay and have various levels of delay.

That's certainly unresponsive. It has nothing to do with 6 names for 0 or for comments that do not match the code.