'Up' was not declared in this scope

I searched this error and found many examples, I just don't understand the answers. Can someone explain how to declare 'Up' before use and why does the Down function work and not the Up? They both worked earlier, then I fixed some of the other code and now I get the error.

void loop() {

// put your main code here, to run repeatedly:
for (int i = 8; i <= 13; i++){
// all outputs (8-13) set to low
digitalWrite(i, LOW);
}
if (digitalRead(button1) == HIGH)
{
Down();
}
else if (digitalRead(button2) == HIGH)
{
Up();
}
}

void Down() {
//if (! limitOpen &! limitDeploy &! limitDown)
if (digitalRead(limitOpen && limitDeploy && limitDown)==LOW)
{
digitalWrite (Open, HIGH);
}
else if (digitalRead(limitOpen &! limitDeploy &! limitDown) == HIGH)
{
digitalWrite (Open, LOW);
digitalWrite (deploy, HIGH);
}
else if (digitalRead(limitOpen && limitDeploy &! limitDown) == HIGH)
{
digitalWrite (deploy, LOW);
digitalWrite (down, HIGH);
}

void Up() {
if (digitalRead(limitUp && limitStow && limitClose) == LOW)
{
digitalWrite (up, HIGH);
}
else if (digitalRead(limitUp &! limitStow &! limitClose) == HIGH)
{
digitalWrite (up, LOW);
digitalWrite (stow, HIGH);
}
else if (digitalRead(limitUp && limitStow &! limitClose) == HIGH)
{
digitalWrite (stow, LOW);
digitalWrite (Close, HIGH);
}
}

First read "Read this before posting a programming question"
The relevant section is this:

Post your complete sketch (program code)! If you don't you waste time while people ask you to do that.
When you post your code put it between

...

tags. You can do that by hitting the </> button above the posting area.

What does your Setup look like?

In the future, to post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your code.
  2. Paste the autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a photograph of the wiring.

Good Luck!

If you followed these instructions, you would have saved me a lot of typing and maybe discovered the issues yourself.

(1) The function Up() is defined within the function Down(). This is a big no-no in C/C++.

(2) digitalRead(...) takes a pin number. Therefore, the following is probably an error:

digitalRead(limitOpen && limitDeploy && limitDown)

Code similar to this occurs multiple times. You may have intended something like this:

digitalRead(limitOpen) && digitalRead(limitDeploy) && digitalRead(limitDown)

(3) Some parentheses might help clarify how you want some of the calculations performed.

Good Luck!

Match all your braces, make sure they are placed properly.
{
}

&! limitStow etc.

&!
Where is this:

Don't take shortcuts unless you know what you are doing.

.

You're missing the close curly brace at the end of the function definition for Down(), as a result the braces are mismatched, the definition for Up() is inside that for Down() (which is invalid syntax too).

When you have an error like that, it's common for the error the compiler gives you to be non-obvious, since the first thing it chokes on ends up being a few layers of logic away.

Thanks everyone!

I did do quite a bit of searching and read the sticky's, it just wasn't making sense to me. I should be able to narrow in on it better now and I posted the entire code so you can see my basic plan. Been 15 years since school, I'll learn from my mistakes.

I have a shop that modifies vehicles for people with disabilities. This will be to fix broken controllers on wheelchair vans. Your patience with me will help someone live a life of more mobility. (No need to fix it for me, just want you to see where I'm headed.)

int button1 = 0;
int button2 = 1;
int limitOpen = 2;
int limitDeploy = 3;
int limitDown = 4;
int limitUp = 5;
int limitStow = 6;
int limitClose = 7;
int Open = 8;
int Close = 9;
int deploy = 10;
int stow = 11;
int down = 12;
int up = 13;



void setup() {
  // put your setup code here, to run once:
pinMode (button1, INPUT);
pinMode (button2, INPUT);
pinMode (limitOpen, INPUT);
pinMode (limitDeploy, INPUT);
pinMode (limitDown, INPUT);
pinMode (limitUp, INPUT);
pinMode (limitStow, INPUT);
pinMode (limitClose, INPUT);
pinMode (Open, OUTPUT);
pinMode (Close, OUTPUT);
pinMode (deploy, OUTPUT);
pinMode (stow, OUTPUT);
pinMode (down, OUTPUT);
pinMode (up, OUTPUT);
}

void loop() {

  // put your main code here, to run repeatedly:
for (int i = 8; i <= 13; i++){
  // all outputs (8-13) set to low
   digitalWrite(i, LOW);
}
if (digitalRead(button1) == HIGH)
{
Down();
}
else if (digitalRead(button2) == HIGH)
{ 
Up();
}
}
  
void Down()  {
//if (! limitOpen &! limitDeploy &! limitDown)
if (digitalRead(limitOpen && limitDeploy && limitDown)==LOW)
 {
 digitalWrite (Open, HIGH);
 } 
 else if (digitalRead(limitOpen &! limitDeploy &! limitDown) == HIGH)
  {
  digitalWrite (Open, LOW);
  digitalWrite (deploy, HIGH);
  }
  else if (digitalRead(limitOpen && limitDeploy &! limitDown) == HIGH)
  {
  digitalWrite (deploy, LOW);
  digitalWrite (down, HIGH);
  }
  

void Up() {
if (digitalRead(limitUp && limitStow && limitClose) == LOW)
  {
  digitalWrite (up, HIGH);
  }
  else if (digitalRead(limitUp &! limitStow &! limitClose) == HIGH)
 {
  digitalWrite (up, LOW);
  digitalWrite (stow, HIGH);
 }
  else if (digitalRead(limitUp && limitStow &! limitClose) == HIGH)
  {
  digitalWrite (stow, LOW);
  digitalWrite (Close, HIGH);
  }
}

Now that I look back on it, the &! is kinda funny. One step at a time.

Dr Azzy, your response came in while I was typing, problem solved. I now see I have many more.

Thanks again for the help.

Bri6462:
I have a shop that modifies vehicles for people with disabilities. This will be to fix broken controllers on wheelchair vans. Your patience with me will help someone live a life of more mobility. (No need to fix it for me, just want you to see where I'm headed.)

  else if (digitalRead(limitOpen && limitDeploy &! limitDown) == HIGH)

Sweet mother of God don't turn your code loose on an actual person in a wheelchair until you have had someone look through it who know what they are doing. And make sure you have a mechanical "Holy shit! Stop everything!" button that cuts the power to stuff.

This line of code, for instance, will perform a digital read of pin 1 or pin 0.

Ha! Don't worry, I'm highly regulated and everything I do gets tested and has an abort method. This is my first project and, even though simple for everyone else on here, I've learned a lot! The completed code is below. It has been tested with LEDs and does what I'm looking for.

int button1 = 0;
int button2 = 1;
int limitOpen = 2;
int limitDeploy = 3;
int limitDown = 4;
int limitUp = 5;
int limitStow = 6;
int limitClose = 7;
int Open = 8;
int Close = 9;
int deploy = 10;
int stow = 11;
int down = 12;
int up = 13;



void setup() {
  // put your setup code here, to run once:
pinMode (button1, INPUT_PULLUP);
pinMode (button2, INPUT_PULLUP);
pinMode (limitOpen, INPUT_PULLUP);
pinMode (limitDeploy, INPUT_PULLUP);
pinMode (limitDown, INPUT_PULLUP);
pinMode (limitUp, INPUT_PULLUP);
pinMode (limitStow, INPUT_PULLUP);
pinMode (limitClose, INPUT_PULLUP);
pinMode (Open, OUTPUT);
pinMode (Close, OUTPUT);
pinMode (deploy, OUTPUT);
pinMode (stow, OUTPUT);
pinMode (down, OUTPUT);
pinMode (up, OUTPUT);
}

void loop() {

  // put your main code here, to run repeatedly:
if (digitalRead(button1) == HIGH)
{
Down();
}
else if (digitalRead(button2) == HIGH)
{ 
Up();
}
else
{
 for (int i = 8; i <= 13; i++){
  // all outputs (8-13) set to low
   digitalWrite(i, HIGH); 
}
}
}
  
void Down()  {
if (digitalRead(limitOpen)==LOW && digitalRead(limitDeploy)==LOW && digitalRead(limitDown)==LOW)
 {
 digitalWrite (Open, LOW);
 } 
 else if (digitalRead(limitOpen)==HIGH && digitalRead(limitDeploy)==LOW && digitalRead(limitDown) == LOW)
  {
  digitalWrite (Open, HIGH);
  digitalWrite (deploy, LOW);
  }
  else if (digitalRead(limitOpen)==HIGH && digitalRead(limitDeploy)==HIGH && digitalRead(limitDown) == LOW)
  {
  digitalWrite (deploy, HIGH);
  digitalWrite (down, LOW);
  }
  else if (digitalRead(limitOpen)==HIGH && digitalRead(limitDeploy)==HIGH && digitalRead(limitDown) == LOW)
  {
  digitalWrite (deploy, HIGH);
  digitalWrite (down, LOW);
  }
}

void Up() {
if (digitalRead(limitUp)==LOW && digitalRead(limitStow)==LOW && digitalRead(limitClose) == LOW)
  {
  digitalWrite (up, LOW);
  }
  else if (digitalRead(limitUp)==HIGH && digitalRead(limitStow)==LOW && digitalRead(limitClose) == LOW)
 {
  digitalWrite (up, HIGH);
  digitalWrite (stow, LOW);
 }
  else if (digitalRead(limitUp)==HIGH && digitalRead(limitStow) == HIGH && digitalRead(limitClose) == LOW)
  {
  digitalWrite (stow, HIGH);
  digitalWrite (Close, LOW);
  }
}

It's very expensive to be paralyzed, controllers for these vans are around $1000. I've gotten a few old vans going again just bypassing the controller and using relay logic, but this adds a new button for every function. The next one I get in will be fixed with a $6 controller and work just like factory. Oh, and it will all be wired through a "Holy shit! Stop everything!" button...I have those in stock.

On another question, the relay board I bought is active low. This seems counter intuitive to me, is there a reason this might be better than active high?

Bri6462:
It's very expensive to be paralyzed, controllers for these vans are around $1000. I've gotten a few old vans going again just bypassing the controller and using relay logic, but this adds a new button for every function. The next one I get in will be fixed with a $6 controller and work just like factory. Oh, and it will all be wired through a "Holy shit! Stop everything!" button...I have those in stock.

On another question, the relay board I bought is active low. This seems counter intuitive to me, is there a reason this might be better than active high?

Just be sure your ass is covered, from a legal perspective. It's very expensive to be paralyzed, and if you can sue the pants off someone who was trying to help you, that can really help with the bills. We live in an astonishingly litigious society - which is hardly surprising when you consider how many legislators were lawyers or their ilk.

This is very common, because it is easier to built N-channel MOSFETs (and NPN BJTs) which switch the low side, and hence are good for driving things wired active low. Better still, if you have a low side switch, you typically turn that on by applying a positive voltage relative to ground. P-channel MOSFETs or PNP BJTs are good for switching the high side, but not only are they more expensive, but they're harder to use too, since you need to drive them by applying a voltage lower than the supply to turn them on, or the same voltage as the supply to turn it off.

Consider switching a 12V relay with a 5v microcontroller. If you use an N-channel enhancement mode logic level MOSFET to switch low side, drain to low side of load, source to ground, gate to micro and you simply put 5v on the gate to turn it on. Easy.
If you want to switch the high side, okay, you put a p-channel enhancement mode logic level MOSFET on the high side, drain to load source to +12v... now for the FET to be off, the gate should be at +12v. Uhoh, we can't connect something at 12v to the microcontroller. So we then need to use another (small) N-channel MOSFET or NPN transistor, just to pull down the gate! So not only is the P-channel fet more expensive for equal performance, we need more parts to drive it too!

There are also a large number of components out there that can only drive a line low, not high, and you have to put pull-up resistors in place to pull the line back up when it's not being driven low. This is called "open drain" or "open collector" - there are many use cases where this makes life much easier.

Thank you for the great response DrAzzy! Now that I understand why, it won't be hard for me to wire for the negative inputs. For the next part of the project I'm going to try to get it to work over bluetooth with an app on the phone for the up and down buttons. This should be frustrating and fun at the same time!