The HEF4094 is very similar to 74HC595, here is the comparison:
We can use the shiftout() function from Arduino IDE to control the HEF4094 since the data input and output pins (one serial input and eight parallel output) for HEF4094 and 74HC595 is exactly the same, additionally the clock input is no different (data is shifted on the LOW to HIGH transitions), with only 3 data pins (CP:Clock Input, STR:Strobe Input, D:Data Input), we can control an almost unlimited amount of outputs.
Code below use to control the 74HC595, the latchPin must first set to LOW before sending data to the Shift Register, the latchPin is then set to HIGH to transfer data to the storage register.
digitalWrite(latchPin, LOW); //Pull latch LOW to send data shiftOut(dataPin, clockPin, MSBFIRST, data); //Send the data digitalWrite(latchPin, HIGH); // Pull latch HIGH to stop sending data
Code below use to control HEF4094, notice that the latchPin (Strobe input) is transitioned from HIGH to LOW.
digitalWrite(latchPin, HIGH); //Pull latch HIGH to send data shiftOut(dataPin, clockPin, MSBFIRST, data); //Send the data digitalWrite(latchPin, LOW); // Pull latch LOW to stop sending data
Here is the fully working sketch for HEF4094, each LED is turn ON and OFF in sequence.
const byte COL_COUNT = 8; //array to hold the data unsigned char sequence[COL_COUNT] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000}; //unsigned char sequence[COL_COUNT] = {1, 2, 4, 8, 16, 32, 64, 128}; //unsigned char sequence[COL_COUNT] = {0x01, 0x02, 0x04, 0x8, 0x10, 0x20, 0x40, 0x80}; //Define which pins will be used for the shift register control //can be any digital pin on the Arduino int latchPin = 8; //Pin connected to STR(pin 1) of HEF4094 int clockPin = 12; //Pin connected to CP(pin 3) of HEF4094 int dataPin = 11; //Pin connected to D(pin 2) of HEF4094 void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { for (int col = 0; col < COL_COUNT; col++) { digitalWrite(latchPin, HIGH); //Pull latch HIGH to send data shiftOut(dataPin, clockPin, MSBFIRST, sequence[col]); //Send the data digitalWrite(latchPin, LOW); // Pull latch LOW to stop sending data delay(500); } }
Sketch below demonstrated how to display 5 digits on the common anode seven segment LED using five HEF4094 Shift Register, you can change the value of DIGIT_COUNT matching your requirement. However you must add leading zero (or blank character) to the number if you are trying to display a number which is less than DIGIT_COUNT.
const byte DIGIT_COUNT = 5; //array to hold the data (0,1,2,3,4,5,6,7,8,9,blank) unsigned char digits[11] = {B11000000, B11111001, B10100100, B10110000, B10011001, B10010010, B10000010, B11111000, B10000000, B10010000, B11111111}; //Define which pins will be used for the shift register control //can be any digital pin on the Arduino int latchPin = 8; //Pin connected to STR(pin 1) of HEF4094 int clockPin = 12; //Pin connected to CP(pin 3) of HEF4094 int dataPin = 11; //Pin connected to D(pin 2) of HEF4094 void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { disp_the_number(12345); delay(1000); disp_the_number(65432); delay(1000); } void disp_the_number(int the_number) { for (int col = 0; col < DIGIT_COUNT; col++) { disp_one_character(getDigit(the_number,col+1)); } } //Extract a digit from an number (integer), eg. getDigit(5678,2) return 6 int getDigit(unsigned int number, int digit) { for (int i=0; i<digit-1; i++) { number /= 10; } return number % 10; } void disp_one_character(char theChar) { digitalWrite(latchPin, HIGH); //Pull latch LOW to send data shiftOut(dataPin, clockPin, MSBFIRST, digits[theChar]); //Send the data digitalWrite(latchPin, LOW); // Pull latch HIGH to stop sending data }