const int SIG = 5;// SIG pin
const int EN = 10;// Enable pin
const int controlPin[4] = {9, 8, 7, 6}; // 4 pins used for binary output
int loopDelay = 100;// delay in loop
const int muxTable[16][4] = {
// s0, s1, s2, s3 channel
{0, 0, 0, 0}, // 0
{1, 0, 0, 0}, // 1
{0, 1, 0, 0}, // 2
{1, 1, 0, 0}, // 3
{0, 0, 1, 0}, // 4
{1, 0, 1, 0}, // 5
{0, 1, 1, 0}, // 6
{1, 1, 1, 0}, // 7
{0, 0, 0, 1}, // 8
{1, 0, 0, 1}, // 9
{0, 1, 0, 1}, // 10
{1, 1, 0, 1}, // 11
{0, 0, 1, 1}, // 12
{1, 0, 1, 1}, // 13
{0, 1, 1, 1}, // 14
{1, 1, 1, 1} // 15
};
void setup() {
for(int i=0; i<4; i++)
{
pinMode(controlPin[i], OUTPUT);// set pin as output
digitalWrite(controlPin[i], HIGH); // set initial state as HIGH
}
pinMode(SIG, OUTPUT);// set SIG pin as output
digitalWrite(SIG, HIGH); // set SIG sends what should be the output
// for low trigger relay it should be LOW
// for HIGH trigger high it should be HIGH
pinMode(EN, OUTPUT);// set EN pin as output
digitalWrite(EN, LOW); // set EN in (enable pin) Low to activate the chip
}
void loop() {
// for(int i=0; i<16; i++)
// {
channelControl(1);
channelControl(5);
// delay(loopDelay);// wait for loopDelay ms
// }
// ledChaserFastWave();
}
void channelControl(int relayChannel)
{
digitalWrite(controlPin[0], muxTable[relayChannel][0]);
digitalWrite(controlPin[1], muxTable[relayChannel][1]);
digitalWrite(controlPin[2], muxTable[relayChannel][2]);
digitalWrite(controlPin[3], muxTable[relayChannel][3]);
}//channelControl end
void ledChaserFastWave() {
// Maju cepat
for (int i = 0; i < 16; i++) {
channelControl(i);
delay(50); // Delay pendek untuk efek chaser cepat
}
// Mundur cepat
for (int i = 14; i >= 0; i--) {
channelControl(i);
delay(50); // Delay pendek untuk efek chaser cepat
}
}