Push button Switches Won't work

Pardon?

Or did you mean

if (DOOR_STATUS==1)
. . .
if (DOOR_STATUS==3)

They're faux 'states' to allow the loops to stay running until user inmput of one of the swithces.

seriously; I don't understand what you mean; and telling a noob to 'try much harder' when they are clearly at the beginning levels of learning is unhelpful tyvm

please explain, or leave off.

when you make an if statement you use
if (expression == expression)
not
if (expression = expression)

That’s very rude, and yes will “leave off”.

Wonder what the root of leave off is ?


These same kind of mistake was pointed out to you 4-5 times in this thread before I pointed out the same errors, hence the “try much harder”.


I'm lost what the current sketch and circuit is. I checked the Tinkercad circuit, but that still has a button connected to GND with a pulldown resistor to GND (that will not work).

There is a new simulator in development, it is called Wokwi.
I tried to put your project in Wokwi, but there is no driver chip or motor yet: https://wokwi.com/arduino/projects/298417502963106314.
Give it a try, you only have to click the start-button in the middle-upper of the screen.

while(digitalRead(BUTTON_CLOSE==LOW)

Whoops

Sack the Prof

@LarryD, telling you to 'leave off' after YOU were incredibly rude was very gentle and in this case rather polite in telling you to go away. = vs == was mentioned once before your comment and once after; and you precisely did NOT inform me what the correction was, you made an arrogant hint.

next cubiclehead2 ; ok, I'm beginning to understand this, like LarryD was so helpful on doubling down; but my code works in tinkercad and passes the arduino 2.0 syntax and bugger.
Do you know another way? is it possible that = and == work in this case with the way I've set up states?

in this case it is'=' is because of the 'if' statement at the end of the previous loop:

void loop() {

  while (DOOR_STATUS==0) {//while the door is closed
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(2, 1);
    lcd.print("***CLOSED***");
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(0, 1);
    lcd.print("Press 1 to Open");
    unsigned long start=millis();
    while(digitalRead(BUTTON_OPEN==LOW)&&(millis()-start<300));

    if (digitalRead(BUTTON_OPEN) == HIGH) {
      digitalWrite(RED_LIGHT, LOW);
      DOOR_STATUS=1;    //change state to opening
    }
  }
 
  if (DOOR_STATUS=1) {  //the door is opening

    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("***OPENING!***");
... ... ...

UKHeliBob see above; and I'm not sure what you are saying now. why is that 'while' statement bad?

@Koepel Thank you ill take a look at that; as to how my switches are wired I got that from here;
see: (https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button)

I'm using the switches as a push down not pullup; again like the above example. so when you push till hits 5v and it works. I think...? lol

I would like to make this better and smoother. but you folks gotta understand I haven't tried my hand at any kind of coding since I was ten with qbasic. a full 27years ago. also

thank you to those that are constructively helping.

It can be very hard, but it is essential to know the difference between a test for equality

A == B

two equal signs jammed up like one dog sniffing another: is the value of A equal to the value of B.

versus

A = B

an assignment, i.e. place the value of B into the variable A

Sry if you already know this at this point. It is hard to see, everyone makes a mistake like this even who know better.

This is why it is recommended to turn up the compiler warnings and read through the verbose output that is produced. Using assignment where the equality test is much more common will generate a warning and you can think, NO, that is what I meant (it might be!) or ARGH! good catch, thass no what I meant at all, thank you.

BTW, spaces are allowed and can make reading code and catching little errors easier, viz:

 if (DOOR_STATUS == 1)…

That kinda thing comes under “style”. Reading (good) code will inform the style you wish to adopt as you learn. Style is meaningless to the final unemotional and basically unintelligent arbiter of meaning in your code, the compiler.

HTH

a7

1 Like

oh hang on!!

@koepel; that was a previous iteration you looked at.

try this one: Circuit design LAUNCH BAY DOOR CONTROL 1.9 | Tinkercad

Okie dok. I replaced all the = with == where there were 'if ' statements.

It did work, but I can see why making sure that is is an equality check vs an assignment is better.
Thanks all.''

that said,
should it not have worked in tinkerCAD previously to this fix?

also; It does seem very clunky on tinkerCAD; like I have to press the UI button a few times for the emulator to recognize that Ive pushed either button... but it will do the desired operations after a couple of clicks.

New code:

// C++ code

//

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

const int MOTOR_CLOSE = 11;  //"motor_forward" from other
const int MOTOR_OPEN = 10;   //"motor_back" from other
const int RED_LIGHT = 14;
const int ORANGE_LIGHT = 15;
const int GREEN_LIGHT = 16;
const int BUTTON_OPEN = 9;
const int BUTTON_CLOSE = 8;
int buttonStateONE = 0;
int buttonStateTWO = 0;
int DOOR_STATUS=0;      //Closed=0, Opening =1, Closing=2, Open=4

 
void setup() {

  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(MOTOR_CLOSE, OUTPUT);
  pinMode(MOTOR_OPEN, OUTPUT);
  pinMode(RED_LIGHT, OUTPUT);
  pinMode(ORANGE_LIGHT, OUTPUT);
  pinMode(GREEN_LIGHT, OUTPUT);
  pinMode(BUTTON_OPEN, INPUT);
  pinMode(BUTTON_CLOSE, INPUT);
  digitalWrite(RED_LIGHT, HIGH);
  digitalWrite(ORANGE_LIGHT, HIGH);
  digitalWrite(GREEN_LIGHT, HIGH);
  lcd.setCursor(1, 0);
  lcd.print("Comand&Control");
  lcd.setCursor(0, 1);
  lcd.print("Launch Bay Doors");
  delay(3500);  //CHANGE ME FOR FINAL TIMING 3-6s?!!!!

  lcd.clear();
  digitalWrite(RED_LIGHT, HIGH);
  digitalWrite(ORANGE_LIGHT, LOW);
  digitalWrite(GREEN_LIGHT, LOW);
  lcd.setCursor(0, 0);
  lcd.print("Launch Bay Doors");
  lcd.setCursor(2, 1);
  lcd.print("***CLOSED***");
  delay(2500);  //CHANGE ME FOR FINAL TIMING 2s?!!!!
}

void loop() {

  while (DOOR_STATUS==0) {//while the door is closed
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(2, 1);
    lcd.print("***CLOSED***");
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(0, 1);
    lcd.print("Press 1 to Open");
    unsigned long start=millis();
    while(digitalRead(BUTTON_OPEN==LOW)&&(millis()-start<300));

    if (digitalRead(BUTTON_OPEN) == HIGH) {
      digitalWrite(RED_LIGHT, LOW);
      DOOR_STATUS=1;    //change state to opening
    }
  }
 
  if (DOOR_STATUS==1) {  //the door is opening

    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("***OPENING!***");
    digitalWrite(MOTOR_OPEN, HIGH);
    digitalWrite(RED_LIGHT, LOW);
    digitalWrite(ORANGE_LIGHT, HIGH);
    digitalWrite(GREEN_LIGHT, LOW);
    delay(4000);//"door" takes 4s to open
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(3, 1);
    lcd.print("***OPEN***");
    digitalWrite(MOTOR_OPEN, LOW);
    digitalWrite(RED_LIGHT, LOW);
    digitalWrite(ORANGE_LIGHT, LOW);
    digitalWrite(GREEN_LIGHT, HIGH);
    delay(2000);

    DOOR_STATUS=4;   //the door is open
  }

  while (DOOR_STATUS==4) {  //while the door is fully open

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(3, 1);
    lcd.print("***OPEN***");
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*  STARBUCK IS *");
    lcd.setCursor(0, 1);
    lcd.print("CLEAR FOR LAUNCH");
    delay(2500);
    lcd.clear();
    lcd.setCursor(3, 1);
    lcd.print("*GO GO GO*");
    delay(2000);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(0, 1);
    lcd.print("Press 2 to Close");
     unsigned long start=millis();
    while(digitalRead(BUTTON_CLOSE==LOW)&&(millis()-start<300));
    
    if(digitalRead(BUTTON_CLOSE)==HIGH){
      DOOR_STATUS=3; //the door is closing
   //add additional LED on/off here
  }
  }

  if (DOOR_STATUS==3) {  //if the door is closing

    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("***CLOSING!***");
    digitalWrite(MOTOR_CLOSE, HIGH);
    digitalWrite(RED_LIGHT, LOW);
    digitalWrite(ORANGE_LIGHT, HIGH);
    digitalWrite(GREEN_LIGHT, LOW);
    delay(4000);//"door" takes 4s to close.
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Launch Bay Doors");
    lcd.setCursor(3, 1);
    lcd.print("**CLOSED**");
    digitalWrite(MOTOR_CLOSE, LOW);
    digitalWrite(RED_LIGHT, HIGH);
    digitalWrite(ORANGE_LIGHT, LOW);
    digitalWrite(GREEN_LIGHT, LOW);
    delay(1500);
    DOOR_STATUS=0;   //the door is closed
  }
}

The Wokwi project is updated to your newest code: https://wokwi.com/arduino/projects/298417502963106314.
As far as I can tell, it does the same thing in Tinkercad as in Wokwi.

To make the sketch responsive, it needs to be changed a lot. For example a Finite State Machine with millis().

I don't understand the official Arduino button example, because I can never remember which pins to use.
wichpins

Therefor, I use two diagonal opposite pins. I'm not the only one, see this Adafruit/Collin video of one minute:

@Koepel Thank you, I will investigate.

Told twice (10 & 12) about the = vs == problem prior to my post.

Told several times to use code tags.

Asked to read the forum guidelines.

Rather then correcting all of your code you continued to make the same mistake and probably wondered why things didn’t work.

I bring up the same errors were still happening and after seeing the above said you need to try harder.

You spewed a vulgar phrase, you tell me to leave off / Fxxx OFF

Not reading forum guidelines stickies, not following posting rules, ignoring answers, refusing to properly post code, spewing a vulgar phrase, yes you need to “try much harder”.

Oh, now in post #33 you finally make changes pointed out at the top of the thread and report things work; go figure :slightly_smiling_face: .

i don't know where live, but where I'm from leave off is not synonymous with eff off.
Basically your whining about watching a learning curve in process. 10+12 Clearly I DID NOT GET IT/ missed it. Quit being a jerk.

I apologized and adapted every time. "spewing vulgar language" jeeze snowflake? Ive been incredibly polite.

Take a hike. you're looking for an issue.

PS "Oh, now in post #33 you finally make changes pointed out at the top of the thread and report things work; go figure :slightly_smiling_face: ." this proves you actually aren't reading the thread.

Looking at the bright side of things, you have hopefully learned the difference between = an ==.

“ Okie dok. I replaced all the = with == where there were 'if ' statements.

It did work, but I can see why making sure that is is an equality check vs an assignment is better.”

it worked before genius.

and there were several spots where = needed to be ==.

Take a hike. you're looking for an issue.

thanks for your "help"

You are welcome.

So you @ 37 years you developed such an attitude ,I think ,(amongst others) you best take the "hike"!

maybe read the whole thread dude.