How to have one function occur with one button high and one button low

Hi everyone hope you all are doing well!

I’m working on a project that requires one limit-switch or button to be High and one Limit or button to be low before sending a high signal to a relay.
I’ve checked out the Button-Tutorial and see how it works, I tried to write something and defined another pin and defined that pin as an output but receive an error that reads "Expected- Initializer-before ‘-’ token.

Hope someone can help with this, do I need to use something other than an If-Statement? If so where can I find a little literature or what should I search for, a while-loop for example?

Thanks for all the help and for all your time!

I tried to write something and defined another pin and defined that pin as an output but receive an error that reads "Expected- Initializer-before '-' token.

So,perhaps you need to fix that. If you need help, send me your crystal ball. Or, post your code.

do I need to use something other than an If-Statement?

Yes. You'll need to use digitalRead() to read the switch states.

PaulS: If you need help, send me your crystal ball.

You flunked telepathy 101, too? So did I. :)

PaulS:

I tried to write something and defined another pin and defined that pin as an output but receive an error that reads "Expected- Initializer-before ‘-’ token.

So,perhaps you need to fix that. If you need help, send me your crystal ball. Or, post your code.

do I need to use something other than an If-Statement?

Yes. You’ll need to use digitalRead() to read the switch states.

So,perhaps you need to fix that. If you need help, send me your crystal ball. Or, post your code.

How do I fix it, can you suggest a good website to visit that explains the error?

Henry_Best:

PaulS: If you need help, send me your crystal ball.

You flunked telepathy 101, too? So did I. :)

I did note that I used the button tutorial so why do you need telepathy? No crystal ball just a request for help, if you don't know how to help why say something?

again how do I take the button tutorial or sketch and have two interactions trigger a relay or LED?

const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin

// variables will change: int buttonState = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }

void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } }

I must be a bad person for asking right??

Ohhh I must know, what a stupid question.

imrobc: I did note that I used the button tutorial so why do you need telepathy?

Because you said you made changes. How are we supposed to know what those changes are?

The code example you posted compiles fine for me. I suspect that it's just the example in question, and not the actual code that is giving you the error message. If you will post the actual code that's giving you the error message, folks can help you. Otherwise, only psychics can help.

When you post code, enclose it in the CODE tag. It looks like a hash-mark in the WYSIWYG editor. It causes your code to display like below.

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

imrobc: Hi everyone hope you all are doing well!

I'm working on a project that requires one limit-switch or button to be High and one Limit or button to be low before sending a high signal to a relay. I've checked out the Button-Tutorial and see how it works, I tried to write something and defined another pin and defined that pin as an output but receive an error that reads "Expected- Initializer-before '-' token.

Hope someone can help with this, do I need to use something other than an If-Statement? If so where can I find a little literature or what should I search for, a while-loop for example?

Thanks for all the help and for all your time!

You asked about an error in code that you wrote or modified but when you don't show the code it does bother people who took time to read about your problem thinking hey, here's someone I might be able to help.

So let's see the code and get that straightened out and -then- go on to the rest.

BTW, yes you would normally use an if statement after you read each switch to make something happen if one switch is on and the other is off (always the same? I doubt it but just checking.) and otherwise not happen.