Help with halefect sensor

Could someone please help me with improving my code for my hall-effect sensor.
Thanks in advance :slight_smile:

int hePin = 12;
int ledPin = 13;

int heState = 0;

void setup(){
  pinMode(ledPin, OUTPUT);
  pinMode(hePin, INPUT);
}

void loop(){
  heState = digitalRead(hePin);

  if (heState == LOW){
    digitalWrite (ledPin, HIGH);
  }

  else {
    digitalWrite (ledPin, LOW);
    
  }
  

}

Could someone please help me with improving my code for my hall-effect sensor.

What needs improving?

Analog input for controlling a engine

Dan_Pan:
Analog input for controlling a engine

Well, I like chocolate ice-cream.

I'm sure my reply makes no sense to you. Yours makes no sense to mine, either.

Well you can be a lot more sucinct:

void loop(){
  digitalWrite (ledPin, ! digitalRead(hePin)) ;
}

You could add some comment lines. "hePin" and "heState" are not descriptive names. You are using ints to store one bit, you might as well use uint8_t and save some memory (not that you're running out just yet). :slight_smile: