However, the less significant the bit gets, thre more I have to define between which values input has to be to enable digitalWrite. Is there a better optimative way?
The reason why I am programming this way is because I am trying to get a linear voltage behavior with a R2R ladder including a op-amp. Since this is easier
Decimal and binary are just to interpretations to a number. The (decimal) number 62 for example is equivalent to 3E (hex) or 00111110 (binary) or 76 (octal) or ... They all represent the same number, but use a different base. In memory they will be exactly the same. So these three statements are the same:
LightuC:
Decimal and binary are just to interpretations to a number. The (decimal) number 62 for example is equivalent to 3E (hex) or 00111110 (binary) or 76 (octal) or ... They all represent the same number, but use a different base. In memory they will be exactly the same. So these three statements are the same:
PORTD = 62;
PORTD = 0x3E;
PORTD = 0b00111110;
Thanks for the help. I have made it working however, PORTD uses pin 0 and 1 which are RX and TX pins. It's not the most ideal but it works and is the most fast solution at the moment.
duykhang2:
Thanks for the help. I have made it working however, PORTD uses pin 0 and 1 which are RX and TX pins. It's not the most idea but it works and is the most fast solution at the moment.
If other pins from the PORT are used in another way, you need to perform a read-modify-write cycle on the port:
// read current content of PORTD
uint8_t currentPort = PORTD;
// clear all pins, except the ones that are used in another way
currentPort &= ((1 << 0) | (1 << 1));
// set your inputs, mask out the pins 0 and 1
currentPort |= input & 0xFC;
// write back the result
PORTD = currentPort;
You might also want to clear the input pins, as setting them will enable/disable the pullups.