In
"Read Two Switches With One I/O Pin" there is:
"There are handy 20K pullup resistors (resistors connected internally between Arduino I/O pins and VCC - +5 volts in the
Arduino's case) built into the Atmega chip upon which Freeduino's are based. They are accessible from software by using the
digitalWrite() function, when the pin is set to an input."
So lets say that I would like to resign from external pull-up resistors.
I have this code:
const int switch1 = 2;
const int switch2 = 3;
const int light1 = 4;
const int light2 = 5;
void setup() {
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(light1, OUTPUT);
pinMode(light2, OUTPUT);
}
void loop() {
if (digitalRead(switch1) == HIGH & digitalRead(switch2) == HIGH) {
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
}
}
And I am planning to change it for that one where I am using internal pull-up resistors:
const int switch1 = 2;
const int switch2 = 3;
const int light1 = 4;
const int light2 = 5;
int state1 ;
int state2;
void setup() {
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(light1, OUTPUT);
pinMode(light2, OUTPUT);
}
void loop() {
digitalWrite(light1, LOW);
state1 = digitalRead(switch1);
digitalWrite(switch2, LOW);
state2 = digitalRead(switch2);
if (state1 == 1 & state2 == 1) {
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
}
}
Is that ok? As I doubt of it but I have no idea how to do it different..