Convert Decimal to Binary and write to pins.


howdy,

i working on large project, , need little bit of guidance. have 7-segment display hooked ic has 4 inputs, , reads binary value consisting of 4 bits. outputs value 7-segment display in proper format display number.

in program, have variable holding number between 0 , 6. there simple way convert number respective binary value , output pins 11-14?

for example, if had number 6 in variable, want convert binary (0110) , output 0 pin11, 1 pin12, 1 pin13, , 0 pin14.

is there simple way this?

any , appreciated.

code: [select]
{
   int var = get_value_between_zero_and_six();
   digitalwrite(11, high && (var & b00001000));
   digitalwrite(12, high && (var & b00000100));
   digitalwrite(13, high && (var & b00000010));
   digitalwrite(14, high && (var & b00000001));
}


i'm assuming want significant bit go digital pin 11.  (your example value of 6 palindrome in binary.)  also, note digital pin 14 labeled analog pin 0 on arduino board.  nothing wrong that, seemed unusual choice.

there many ways calculate second argument digitalwrite().  i chose form (1 && (var & bitmask)), evaluates 1 or 0 appropriately, without shifting operations.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Convert Decimal to Binary and write to pins.


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums