AnalogWrite not working in If Statement

Arduino Uno with ATMega328P Processor.AnalogWrite not working properly in If statement. It changes the brightness of Led like there isnt any if statements at all. There are 2 potentiometers to create an intervall in which to program increases the brightness of led starting 40% of maxi. When its lower then min value led is closed.

int ledPin = 6;
int sensorPot = 1; // its a potentiometer for now
int maxPot = 7; // potentiometer 
int minPot = 3; // potentiometer
int fortypercent = 255*0.4;
int brightness = 0;

void setup() {

  pinMode(ledPin, OUTPUT);
  pinMode(sensorPot, INPUT);
  pinMode(maxPot, INPUT);
  pinMode(minPot, INPUT);

  Serial.begin(9600);

}
void loop() {

  int start = analogRead(minPot);
  int maxVal = analogRead(maxPot);
  int sensor = analogRead(sensorPot);
  Serial.println(sensor/4);
   Serial.println(start/4);
  Serial.println(maxVal);
////  
if(sensor/4 > start/4){
    analogWrite(ledPin,sensor/4);
  }
else if(sensor = baslangic){
  analogWrite(ledPin,LOW);
  }
else if ((start < sensor < maxVal)) {
  brightness = sensor/4 - fortypercent;
  analogWrite(ledPin,brightness); 
  }else if (sensor = maxVal){
    analogWrite(ledPin , 255);
    }



}

That's interesting (and unlikely) - what proof do you have?

aomerk:
Arduino Uno with ATMega328P Processor cant execute AnalogWrite in If statement.

How do you know? What actually happens?

Post a sample of the output when you run the program.

...R

(deleted)

Code: [Select]

analogWrite(analogOutPin, LOW);

nonsense!
Code: [Select]

analogWrite(analogOutPin, 0);

Perhaps!

You need to look at the source of analogWrite for the AVR processors, particularly for an argument of zero (aka LOW) :wink:

(deleted)

else if(sensor = baslangic){

That is an assignment statement, not a comparison. = != ==

else if ((start < sensor < maxVal)) {

That is NOT how to test that a value is in a range. That is testing that start < sensor, which is either true or false, is less than maxVal. Unless maxVal is less than 2, that statement will always be true.