Hi All,
Glad your here.
I can do the CD4051BE tutorials but I need a demonstration of code for turning one or up to 4 of the leds on for 50ms and then off for another delay. I'll be using this to control relays which I can do without demuxing.
Every tutorial that I've looked at and followed shows how to cycle repeatedly through the 8 instead of what I need to know.
I'll post a sketch that I'm running with a bread boarded circuit that I'm sure could be altered to show what I need but, would appreciate a simple example of how it's done. For just one of the 8 LEDs would be fine.
Many thanks,
Donald
int totalChannels = 8;
int addressA = 8;
int addressB = 9;
int addressC = 10;
int outputpin = 13;
int A = 0; //Address pin A
int B = 0; //Address pin B
int C = 0; //Address pin C
void setup() {
// Prepare address pins for output
pinMode(addressA, OUTPUT);
pinMode(addressB, OUTPUT);
pinMode(addressC, OUTPUT);
// Prepare write/output pin
pinMode(outputpin, OUTPUT);
}
void loop() {
//Select each pin and read value
for(int i=0; i<totalChannels; i++){
A = bitRead(i,0); //Take first bit from binary value of i channel.
B = bitRead(i,1); //Take second bit from binary value of i channel.
C = bitRead(i,2); //Take third bit from value of i channel.
//Write address to mux
digitalWrite(addressA, A);
digitalWrite(addressB, B);
digitalWrite(addressC, C);
//Write value
digitalWrite(outputpin, 1);
//Set delay to 1000 and then to 1 to see difference
delay(1000);
}
}