I am using an ATtiny85 as a micro-controller. I am trying to read two inputs at around 3 V each and output 5 V for every "on" input (more than 1V). I'm using PINB0 & PINB1 for input and PINB3 & PINB4 for output. The problem is when both PINB0 & PINB1 are on, I get two 5 V outputs, but when only one of the is on, I only get 2 V, I'm trying to fix that so I get 5V output.
Here is my code:
#inlude <avr/io.h>
#include <stdint.h>
int main(void)
{
// set pin 0 to input (pi signal 0)
DDRB &= ~(1 << PINB0);
PORTB &= 0 << PINB0;
// set pin 1 to input (pi signal 1)
DDRB &= ~(1 << PINB1);
PORTB &= 0 << PINB1;
//set pin 3 to output of 0
DDRB |= 1 << PINB3;
PORTB &= 0 << PINB3;
//set pin 4 to output of 1
DDRB |= 1 << PINB4;
PORTB &= 0 << PINB4;
while (1)
{
if (bit_is_clear(PINB, 0) && bit_is_clear(PINB, 1))
{
PORTB &= 0 << PINB3; //output zero volts
PORTB &= 0 << PINB4; //output zero volts
}
else if (bit_is_clear(PINB, 0) && !(bit_is_clear(PINB, 1)))
{
PORTB &= 0 << PINB3; //output zero volts
PORTB |= 1 << PINB4; //output 5 volts
}
else if (!(bit_is_clear(PINB, 0)) && bit_is_clear(PINB, 1))
{
PORTB |= 1 << PINB3; //output 5 volts
PORTB &= 0 << PINB4; //output zero volts
}
else
{
PORTB |= 1 << PINB3; //output 5 volts
PORTB |= 1 << PINB4; //output 5 volts
}
}
}