DDRB = 0b00000000; // Configure all Port B pins as inputs
PORTB = 0b00111111; // Enable internal pull-ups for pins PB0 to PB5
DDRC = 0b00000000; // Configure all Port C pins as inputs
DDRD = 0b00001100; // Configures Port D pins PD2, PD3 as outputs
void setup() {
// put your setup code here, to run once:
DDRB = 0b00000000;
PORTB = 0b00000011;
DDRC = 0b00000000;
DDRD = 0b00011100;
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(8)==1) {
digitalWrite(2, HIGH);
} else {
digitalWrite(2, LOW);
}
if (digitalRead(9)==1) {
digitalWrite(3, HIGH);
} else {
digitalWrite(3, LOW);
}
}
Does this work?
PINB0 is 0 and PINB1 is 1. They are the bit positions in the register for the associated pins. They are NOT the pin numbers that the digitalWrite API expects.
/Input
#define Buton1 8
#define Buton2 9
//Output
#define RL1 2
#define RL2 3
void setup() {
// put your setup code here, to run once:
DDRB = 0b00000000;
PORTB = 0b00000011;
DDRC = 0b00000000;
DDRD = 0b00011100;
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(Buton1)==1) {
digitalWrite(RL1, HIGH);
} else {
digitalWrite(RL1, LOW);
}
if (digitalRead(Buton2)==1) {
digitalWrite(RL2, HIGH);
} else {
digitalWrite(RL2, LOW);
}
}
Does this not work? Again, the nomenclature you are trying to use is not appropriate for the API you are trying to use. You have to either use pin numbers like digitalWrite and digitalRead expect or don't use those functions.
I'm a beginner in the arduino, I made some assembly programs for the atmega328 and I'm more comfortable saying that the led is on PB5 than saying that the led is on 13.
It confused me at times.
I would like to define that the led is on PB5 and that a button is on PB4 and be able to write
digitalRead(PB4) to read the button state and not have to use digitalRead(12)