/*
*** CD74HC4067 16 Channel Multiplexer ***
*/
const int buttonPin = 13; // the number of the pushbutton pin
const int led3 = 12; // the number of the LED pin
const int led2 = 11;
const int led1 = 10;
const int led0 = 9;
//const int pwmPin = 3;
const int S0 = A0;
const int S1 = A1;
const int S2 = A2;
const int S3 = A3;
int buttonState = 0; // variable for reading the pushbutton status
int counter=0;
//int fadeValue=0;
void setup() {
pinMode(led3, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led0, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S0, OUTPUT);
pinMode(buttonPin, INPUT);
//pinMode(pwmPin, OUTPUT);
digitalWrite(S3,0);
digitalWrite(S2,0);
digitalWrite(S1,0);
digitalWrite(S0,0);
Serial.begin(9600);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
moveNext(); // ********
delay(400);
}
}
void moveNext(){
if (counter < 15) counter += 1; else counter=0;
bool a = bitRead(counter, 0); // **********************
bool b = bitRead(counter, 1);
bool c = bitRead(counter, 2);
bool d = bitRead(counter, 3);
digitalWrite(S0, a);
digitalWrite(S1, b);
digitalWrite(S2, c);
digitalWrite(S3, d);
digitalWrite(led0, a); // 9
digitalWrite(led1, b); // 10
digitalWrite(led2, c); // 11
digitalWrite(led3, d); // 12
Serial.print(counter); Serial.print(" = ");
Serial.print(a);
Serial.print(b);
Serial.print(c);
Serial.println(d);
} //////////////////////////////////////////////////////////////
// https://drive.google.com/file/d/1PM90YH8QxyUyIX0b23-MMU2vMCeEzWcp/viewLoading
cd74hc4067
cd74hc4067