//01001110
//01000001
//01001110
//01000100
//01001111
#include <SPI.h>
#define DATA_PIN 10 // Data Serial Input
#define LATCH_PIN 11 // Storage Register Clock Input
#define CLOCK_PIN 13 // Shift Register Clock Input
#define RegNumb 2 // shift register #
const uint8_t RegPinNumber = RegNumb * 8; // Register Pin #
bool registers[RegPinNumber];
char Word[] = "BOB"; // Word to translate to binary code
void setup()
{
// Set the control pins as outputs
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
// Clear the register states
clearRegisters();
// Write the initial register states
writeRegisters();
}
void loop()
{
// Loop through each character in the Word
for (uint8_t i = 0; i < strlen(Word); i++) {
// Clear the register states
clearRegisters();
// Set the register states to match the ASCII representation of the current character
for (uint8_t j = 0; j < 8; j++) {
setRegisterPin(j, bitRead(Word[i], j));
}
// Write the register states
writeRegisters();
// Wait for 2 seconds before moving on to the next character
delay(2000);
}
}
void clearRegisters() {
// Reset all register pins to LOW
for (int i = RegPinNumber - 1; i >= 0; i--) {
registers[i] = LOW;
}
}
void setRegisterPin(int index, int value) {
// Set an individual pin to HIGH or LOW
registers[index] = value;
}
void writeRegisters() {
// Set and display the register states
digitalWrite(LATCH_PIN, LOW); // Pull latch LOW to start sending data
// Send the register states via SPI
for (int i = RegPinNumber - 1; i >= 0; i--) {
digitalWrite(CLOCK_PIN, LOW); // Pull clock LOW to prepare for data
digitalWrite(DATA_PIN, registers[i]); // Send the current register state
digitalWrite(CLOCK_PIN, HIGH); // Pull clock HIGH to shift the register state
}
digitalWrite(LATCH_PIN, HIGH); // Pull latch HIGH to stop sending data and update the output
}