Pages: [1]   Go Down
Author Topic: single potentiometer lock system (value not ignored as it ought to be) help plz  (Read 354 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks smiley
Logged

Pages: [1]   Go Up
Jump to: