Hi everyone,
i'm making a small test by using a register 74HC165, 3 switchers and a led matrix.
The idea is to use the design for Arduino UNO projects where i need many i/o
So the test is simple :
1- Put the wished configuration of the switchers
for exp.:
switcher 1 is on High position
switcher 2 is on low position
switcher 3 is on low position
2- A smile face then is played on the matrix according to the configuration of the switchers chosen previously
right now it's not working. I think i can not read / find away to read the given values from register.
Could you please kindly help. Thanks.
Here the code:
#include <SPI.h>
#include <LedControl.h>
//74HC165 for switchers
const int dataPin2 = 8; /* Q7 */
const int clockPin2 = 9; /* CP */
const int latchPin2 = 12; /* PL */
int switcherstatus = 000;
int DIN = 11;
int CS = 10;
int CLK = 13;
LedControl lc = LedControl(DIN, CLK, CS, 0);
void setup()
{
Serial.begin(115200);
pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, INPUT);
lc.shutdown(0, false);
lc.setIntensity(0, 15);
}
void loop()
{
digitalWrite(latchPin2, LOW);
digitalWrite(latchPin2, HIGH);
for (int i = 0; i < 3; i++)
{
switcherstatus = digitalRead(dataPin2);
digitalWrite(clockPin2, HIGH);
digitalWrite(clockPin2, LOW);
}
Serial.print(switcherstatus);
if (switcherstatus == 100) {
smile();
}
}
void smile()
{
byte SMILE[8] = {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, SMILE[i]);
}
}
void sad()
{
byte SAD[8] = {0x3C, 0x42, 0xA5, 0x81, 0x99, 0xA5, 0x42, 0x3C};
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, SAD[i]);
}
}
Below is my wokwi project: