Dan_Pan
December 8, 2015, 12:31pm
1
Could someone please help me with improving my code for my hall-effect sensor.
Thanks in advance
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);
}
}
Dan_Pan
December 8, 2015, 12:37pm
3
Analog input for controlling a engine
system
December 8, 2015, 12:39pm
4
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.
MarkT
December 8, 2015, 1:16pm
5
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).