the "and" part in my code doesn't want to work.

Hi i'm making a game for a school project but I can't find my error. I want to check if the value of my potentiometer is between two other value's with a "if" and "and" function but the and part doesn't work.

Can someone help me thanks in advance.

//--------------------------------PINS--------------------------------
//buzzer
const int buzzer = 2;
//display
int pins[] = {23, 25, 27, 29, 31, 33, 35, 37};
//leds
const int led1 = 10;
const int led2 = 11;
const int led3 = 12;
//Potentiometers
int pot1 = A3;
int pot2 = A2;
int pot3 = A1;
//knop
const int knop = 8;

//------------------------Nummers klaarzetten------------------------
//0 = 0b11111100 = 0xFC
//1 = 0b00100100 = 0x24
//2 = 0b01111010 = 0x7A
//3 = 0b01101110 = 0x6E
//4 = 0b10100110 = 0xA6
//5 = 0b11001110 = 0xCE
//6 = 0b11011110 = 0xDE
//7 = 0b01100100 = 0x64
//8 = 0b11111110 = 0xFE
//9 = 0b11101110 = 0xEE
const int numbers[] = {0xfc, 0x24, 0x7a, 0x6e, 0xa6, 0xce, 0xde, 0x64, 0xfe, 0xee};

//Gamenumbers
long randNumber1;
long randNumber2;
long randNumber3;
int laag1;
int hoog1;
int laag2;
int hoog2;
int laag3;
int hoog3;

void setup() {
display(0);
Serial.begin(9600);
Serial.println("Serial has started");
for (int i = 0; i <= 7; i++) {
pinMode(pins*, OUTPUT);*

  • }*
  • pinMode(buzzer, OUTPUT);*
  • pinMode(led1, OUTPUT);*
  • pinMode(led2, OUTPUT);*
  • pinMode(led3, OUTPUT);*
  • pinMode(knop, INPUT_PULLUP);*
  • randomSeed(analogRead(A15));*
  • randomSeed(analogRead(A14));*
  • randomSeed(analogRead(A13));*
  • //-----------------//level1-------------------------*
  • randNumber1 = random(950);*
  • Serial.println(randNumber1);*
  • randNumber2 = random(950);*
  • Serial.println(randNumber2);*
  • randNumber3 = random(950);*
  • Serial.println(randNumber3);*
  • int x = 100;*
  • int laag1 = randNumber1 - x;*
  • int hoog1 = randNumber1 + x;*
  • int laag2 = randNumber2 - x;*
  • int hoog2 = randNumber2 + x;*
  • int laag3 = randNumber3 - x;*
  • int hoog3 = randNumber3 + x;*
    }
    void loop() {
  • int waarde_pot1 = analogRead(pot1);*
  • int waarde_pot2 = analogRead(pot2);*
  • int waarde_pot3 = analogRead(pot3);*
  • // Aanwijzingen*
  • if ((analogRead(pot1) > laag1) and (analogRead(pot1) < hoog1)) {*
  • digitalWrite(led1, HIGH);*
  • } else {*
  • digitalWrite(led1, LOW);*
  • }*

Read How to post code properly and fix up your code with [code]...[/code] tags. It'll make more sense and be easier to read.

Pete

Every { needs a }

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

have you tried to print out what analogRead returns on the two pots?

Yes bulldoglowell I printed everything and it all seems fine.

for example.

when I just try:

 if (analogRead(pot1) > laag1) {
    digitalWrite(led1, HIGH);
  } else {
    digitalWrite(led1, LOW);
  }

that works fine.

I found the problem it's something with the value's.

Bc I tried this:

const int led1 = 10;
int pot1 = A3;

long randNumber1;
long randNumber2;
long randNumber3;
int laag1;
int hoog1;
int laag2;
int hoog2;
int laag3;
int hoog3;
void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  randomSeed(analogRead(A15));
  randomSeed(analogRead(A14));
  randomSeed(analogRead(A13));
  randNumber1 = random(950);
  Serial.println(randNumber1);

  randNumber2 = random(950);
  Serial.println(randNumber2);

  randNumber3 = random(950);
  Serial.println(randNumber3);
  int x = 100;
  int laag1 = randNumber1 - x;
  int hoog1 = randNumber1 + x;
  int laag2 = randNumber2 - x;
  int hoog2 = randNumber2 + x;
  int laag3 = randNumber3 - x;
  int hoog3 = randNumber3 + x;
}

void loop() {
  // put your main code here, to run repeatedly:
  if ((analogRead(pot1) > 500) and (analogRead(pot1) < 600)) {
    digitalWrite(led1, HIGH);
  } else {
    digitalWrite(led1, LOW);
  }
}