Author Topic: output binary to selected pins  (Read 1842 times)

0 Members and 1 Guest are viewing this topic.

Offline blackbeardTopic starter

  • Supreme Robot
  • *****
  • Posts: 575
  • Helpful? 4
output binary to selected pins
« on: October 24, 2010, 06:39:32 PM »
ok so i have an led cube i'm trying to program. essentially i've got 2 8 bit dmux connected to 3 i/o on the arduino and the inputs connected to 2 other pins. my problem is that i don't always want to have this kind of thing in my code. i'd much rather just say a binary number to write to the pins that the mux is connected to

digitalWrite(muxS1, HIGH);
digitalWrite(muxS2, LOW);
digitalWrite(muxS3, LOW);

digitalWrite(muxS1, LOW);
digitalWrite(muxS2, HIGH);
digitalWrite(muxS3, LOW);


"sure, you can test your combat robot on kittens... But all your going to do is make kitten juice"

First step: Build androids with AI
Next step: Give them vaginas

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
    • Personal Website
Re: output binary to selected pins
« Reply #1 on: October 25, 2010, 07:44:21 AM »
How about

for(int value = 0; value <=7; value++){

digitalWrite(muxS1, bitRead(value, 0));
digitalWrite(muxS2, bitRead(value, 1));
digitalWrite(muxS3, bitRead(value, 2));

}

That will set the three pins to the state described by the lower three bits in the value number. With the loop, it will cycle through all the outputs of your demux.
« Last Edit: October 25, 2010, 07:47:23 AM by madsci1016 »

Offline blackbeardTopic starter

  • Supreme Robot
  • *****
  • Posts: 575
  • Helpful? 4
Re: output binary to selected pins
« Reply #2 on: October 25, 2010, 08:29:41 AM »
How about

for(int value = 0; value <=7; value++){

digitalWrite(muxS1, bitRead(value, 0));
digitalWrite(muxS2, bitRead(value, 1));
digitalWrite(muxS3, bitRead(value, 2));

}

That will set the three pins to the state described by the lower three bits in the value number. With the loop, it will cycle through all the outputs of your demux.

thanks allot. that's allot better then the code i am using now which looks something like this it's random but that's just so i can test the whole cube.

  count = random(0,8);
  row = bin[count];
  mux1= row & 0x01;
  mux2 = (row>>1) & 0x01;
  mux3 = (row>>2) & 0x01;
  digitalWrite(7, mux1);
  digitalWrite(8, mux2);
 digitalWrite(9, mux3);
"sure, you can test your combat robot on kittens... But all your going to do is make kitten juice"

First step: Build androids with AI
Next step: Give them vaginas

 


Get Your Ad Here

data_list