trying to establish a condition in order to turn on other led

Hello

im new to programming and im sorry for the stupid question but .

i have 3 led on my circuit
1 . first led is on/off indicator for system
2. blue led
3. red led

im trying to create a condition that when on/off led is set to LOW the other led cannot turn on unless

the on/off led is set to high via serial command

thank you guys

elidor

//Program by Jeremy Blum
//www.jeremyblum.com
//Uses commands from computer to control arduino

int ledPin = 13;
int coolPin = 12;
int heatPin = 11;

void setup()
{
//Create Serial Object
Serial.begin(9600);

pinMode(ledPin, OUTPUT);
pinMode(coolPin, OUTPUT);
pinMode(heatPin, OUTPUT);

}

void loop()
{
//Have the arduino wait to receive input
while (Serial.available() == 0);

//Read the Input
int val = Serial.read() - '0';

if (val == 1)
{
Serial.println("Led is On");
digitalWrite(ledPin, HIGH);
}
else if (val == 0)
{
Serial.println("Led is Off");
digitalWrite(ledPin, LOW);
digitalWrite(coolPin, LOW);
digitalWrite(heatPin, LOW);
}

// condition if led pin off nothing else is on
if (val ==2 )
{

Serial.println("cool") ;
digitalWrite(heatPin, LOW) ;
digitalWrite(coolPin, HIGH) ;
}
else if (val==3)
{
Serial.println("heat");
digitalWrite(coolPin, LOW);
digitalWrite(heatPin, HIGH);

}
}

TheUnnamedCircuit.ino (1.46 KB)

im trying to create a condition that when on/off led is set to LOW the other led cannot turn on unless

Why do you talk about on/off and blue and red LEDs when the pin names are ledPin, coolPin, and heatPin?

What, exactly, is the problem? It is not difficult to keep track of the state of a pin, and turn one pin on if another pin is off.

It is much easier for everyone if you post your code properly and remove unnecessary white space

//  _ ___ _______     ___ ___ ___  ___ _   _ ___ _____ ___ 
// / |_  )__ /   \   / __|_ _| _ \/ __| | | |_ _|_   _/ __| 
// | |/ / |_ \ |) | | (__ | ||   / (__| |_| || |  | | \__ \ 
// |_/___|___/___/   \___|___|_|_\\___|\___/|___| |_| |___/ 
// 
// The Unnamed Circuit
// 
// Made by elidor zamir
// License: CC-BY-SA 3.0
// Downloaded from: https://123d.circuits.io/circuits/992276-the-unnamed-circuit

//Program by Jeremy Blum
//www.jeremyblum.com
//Uses commands from computer to control arduino

int ledPin = 13;
int coolPin = 12;
int heatPin = 11;

void setup()
{
  //Create Serial Object
  Serial.begin(9600);
  
  pinMode(ledPin, OUTPUT);
  pinMode(coolPin, OUTPUT);
  pinMode(heatPin, OUTPUT);
}

void loop()
{
  //Have the arduino wait to receive input
  while (Serial.available() == 0);
  
  //Read the Input
  int val = Serial.read() - '0';

  if (val == 1) 
  {
    Serial.println("Led is On"); 
    digitalWrite(ledPin, HIGH);
  }
  else if (val == 0)
  {
    Serial.println("Led is Off");
    digitalWrite(ledPin, LOW);
    digitalWrite(coolPin, LOW);
    digitalWrite(heatPin, LOW);
  }

  // condition if led pin off nothing else is on 
  if (val ==2 ) 
  {
    
    Serial.println("cool") ;
    digitalWrite(heatPin, LOW) ;
    digitalWrite(coolPin, HIGH) ;
  }
  else if (val==3)
  {
    Serial.println("heat");
    digitalWrite(coolPin, LOW);
    digitalWrite(heatPin, HIGH);
    
   }
}

I'm finding it hard to relate your question to your code because I don't see any attempt at the logic you want to apply - but I may well have missed something.

And when I read this

im trying to create a condition that when on/off led is set to LOW the other led cannot turn on unless

the on/off led is set to high via serial command

I find myself wondering what could turn the LED on, apart from an instruction from Serial.

Unless you need to use the received character as a number there is no value in converting it to an INT. your tests could just as easily be if (val == '1')

...R
Serial Input Basics