Hello all
As you requested, here are the squematic and the code of the project.
I hope it is ok and lead us to the problem…
About the shift register use for this project, even when there are easier ways to acomplish it, I must be honest and say the following, when I fell in love with Arduino and its possibilities a few months ago, I did not know anything about electronics (still I don’t… but working hard the get better), I make a lot of research about what I wanted to do at that moment. The ICs, in this case the shift registers, had been for me a mistery, a little black “thing” in a complicated PCB and I decided to use this “hardest” method as a way to learn… maybe not the best decision, but at the stage I’m now, I think it does’nt worth to change the method (because the learning).
Honestly, I’ve learn a lot and the most important is I’m starting to see the circuits as a not so impossible challenge… hard, but not impossible.
You can’t imagine how grateful I am with all you… your help and interest.
Please help me to acomplish this, I promise to take all the neccesary advice… by the way, the 74HC165’s are on its way.
How do I attach images the way PaulRB did?.. anyway I attached the squematic by the attach option.
Please remember that the shift registers are 74HC595 and cd4021BE… (the 123D software do not have available the second one to include in the squematic, so I use another 16 pins IC, so watch for correct pins)
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;
#include <SPI.h>
#include <Wire.h>
#include <ShiftRegister74HC595.h>
long time = 0; // the last time the output pin was toggled
long debounce = 300; // the debounce time, increase if the output flickers
ShiftRegister74HC595 sr1 (1, 6, 5, 4);
//Define variables to hold the data
//for each shift register.
//starting with non-zero numbers can help
//troubleshoot
byte switchVar1 = 0; //10000000
void setup() {
//start serial
Serial.begin(9600);
//define pin modes
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
sr1.set(0, LOW);
}
void loop() {
//Pulse the latch pin:
//set it to 1 to collect parallel data
digitalWrite(latchPin,1);
// digitalWrite(latchPinVar2,1);
// digitalWrite(latchPinVar3,1);
//set it to 1 to collect parallel data, wait
delayMicroseconds(1);
//set it to 0 to transmit data serially
digitalWrite(latchPin,0);
//while the shift register is in serial mode
//collect each shift register into a byte
//the register attached to the chip comes in first
switchVar1 = shiftIn(dataPin, clockPin);
Serial.println(switchVar1, BIN);
delay(500);
for (int n=0; n<6; n++)
{
if (switchVar1 & (1 << 6) ){
}
lcd.setBacklight(HIGH);
{if (switchVar1 & (10) ){Serial.println("Down Arrow"), sr1.set(6, HIGH);} }
{if (switchVar1 & (100) ){Serial.println("Magnifier"), sr1.set(5, HIGH);} }
{if (switchVar1 & (1000) ){Serial.println("Up Arrow"), sr1.set(4, HIGH);} }
{if (switchVar1 & (10000) ){Serial.println("Events 4"), sr1.set(3, HIGH);} }
{if (switchVar1 & (100000) ){Serial.println("Events 3"), sr1.set(2, HIGH);} }
{if (switchVar1 & (1000000) ){Serial.println("Events 2"), sr1.set(1, HIGH);} }
{if (switchVar1 & (10000000) ){Serial.println("Events 1"), sr1.set(0, HIGH);} }
{if (switchVar1 & (10000000) ){Serial.println("X"), sr1.set(0, HIGH);} }
}
}
//------------------------------------------------end main loop
////// ----------------------------------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0
byte shiftIn(int myDataPin, int myClockPin) {
int i;
int temp = 0;
int pinState;
byte myDataIn = 0;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);
//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop
//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
for (i=7
; i>=0; i--)
{
digitalWrite(myClockPin, 0);
//delayMicroseconds(2);
temp = digitalRead(myDataPin);
if (temp) {
pinState = 1;
//set the bit to 0 no matter what
myDataIn = myDataIn | (1 << i);
}
else {
//turn it off -- only necessary for debuging
//print statement since myDataIn starts as 0
pinState = 0;
}
//Debuging print statements
//Serial.print(pinState);
//Serial.print(" ");
//Serial.println (dataIn, BIN);
digitalWrite(myClockPin, 1);
}
//debuging print statements whitespace
//Serial.println();
//Serial.println(myDataIn, BIN);
return myDataIn;
}