Skip to content

Instantly share code, notes, and snippets.

@assertchris
Created April 3, 2013 21:26
Show Gist options
  • Select an option

  • Save assertchris/5305496 to your computer and use it in GitHub Desktop.

Select an option

Save assertchris/5305496 to your computer and use it in GitHub Desktop.
Arduino N-Tier Demultiplexing
int controlPin1 = 2;
int controlPin2 = 3;
int controlPin3 = 4;
int controlPin4 = 5;
int controlPin5 = 6;
int controlPin6 = 7;
int signalPin = 9;
int multiplexers[2][3] = {
{0, 0, 0},
{0, 0, 1}
};
int outputs[8][3] = {
{0, 0, 0},
{0, 0, 1},
{0, 1, 0},
{0, 1, 1},
{1, 0, 0},
{1, 0, 1},
{1, 1, 0},
{1, 1, 1}
};
void setup()
{
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(controlPin3, OUTPUT);
pinMode(controlPin4, OUTPUT);
pinMode(controlPin5, OUTPUT);
pinMode(controlPin6, OUTPUT);
pinMode(signalPin, OUTPUT);
}
void loop()
{
for (int i = 0; i < 2; i++)
{
digitalWrite(controlPin1, multiplexers[i][0]);
digitalWrite(controlPin2, multiplexers[i][1]);
digitalWrite(controlPin3, multiplexers[i][2]);
for (int j = 0; j < 8; j++)
{
digitalWrite(controlPin4, outputs[j][0]);
digitalWrite(controlPin5, outputs[j][1]);
digitalWrite(controlPin6, outputs[j][2]);
for (int k = 0 ; k <= 255; k += 16)
{
analogWrite(signalPin, k);
delay(30);
}
for (int k = 255 ; k >= 0; k -= 16)
{
analogWrite(signalPin, k);
delay(30);
}
}
}
}
@assertchris
Copy link
Copy Markdown
Author

Errata: apparently I should have used byte as the type for the arrays, and there are better alternatives to the delay function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment