Go Down

Topic: single potentiometer lock system (value not ignored as it ought to be) help plz (Read 391 times) previous topic - next topic

Eddiexyx2

this was supposed to be the code for a single potentiometer lock system but i keep getting the error "value not ignored as it ought to be" and since im still new at using the arduino and programming in in genaral i dont know what to do. Could anyone plz give me some tips on changes i should make to the code.

int r1 = A0;
int r2 = A1;
int button = 6;
int led1 = 13;
int led2 = 12;
int led3 = 11;
void setup()
{
  Serial.begin(9600);
  pinMode(button,INPUT);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
}

void loop()
{
int val1 = analogRead(r1);

  if(val1 == 598 && digitalRead(button) == HIGH) Serial.println( "acess1 clear")
  && digitalWrite(led1,HIGH);
 
  if(val1 == 450 && digitalRead(button) == HIGH && digitalWrite(led1,HIGH))
  Serial.println( "acess2 clear") && digitalWrite(led2,HIGH);
 
  if(val1 == 1023 && digitalRead(button) == HIGH && digitalWrite(led2,HIGH))
  Serial.println( "acess granted") && digitalWrite(led3,HIGH) ;
 
 
   Serial.println(val1);
   delay(1000);
}

johnwasser

You seem to be confused about the proper use of the Logical And (&&) operator.  I think this is what you might have intended:

Code: [Select]

void loop()
{
  int val1 = analogRead(r1);

  if(val1 == 598 && digitalRead(button) == HIGH) {
    Serial.println( "acess1 clear");
    digitalWrite(led1,HIGH);
  }

  if(val1 == 450 && digitalRead(button) == HIGH) {
    digitalWrite(led1,HIGH);
    Serial.println( "acess2 clear");
    digitalWrite(led2, HIGH);
  }

  if(val1 == 1023 && digitalRead(button) == HIGH) {
    digitalWrite(led2, HIGH);
    Serial.println( "acess granted");
    digitalWrite(led3,HIGH);
  }

  Serial.println(val1);
  delay(1000);
}


You got the error because you tried to AND the result of digitalWrite() into an expression.  Since digitalWrite() returns a void value (no value) it can't be use in an expression.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy