const int hall1Pin = 7; // the number of the hall effect sensor pin
const int ledPin1 = 2; // the number of the LED pin
const int hall2Pin = 10;
const int ledPin2 = 4;
int hall1State = 0;
int hall2State = 0; // variable for reading the hall sensor status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize the hall effect sensor pin as an input:
pinMode(hall1Pin, INPUT);
pinMode(hall2Pin, INPUT);
}
void loop(){
// read the state of the hall effect sensor:
hall1State == digitalRead(hall1Pin);
if (hall1State = HIGH) {
// turn LED on:
digitalWrite(ledPin1,LOW);
}
else {
// turn LED off:
digitalWrite(ledPin1, HIGH);
}
hall2State = digitalRead(hall2Pin);
if (hall2State == HIGH) {
// turn LED on:
digitalWrite(ledPin2,LOW);
}
else {
// turn LED off:
digitalWrite(ledPin2, HIGH);
}
}
Comments
Please log in or sign up to comment.