//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 13;
////Pin connected to DS of 74HC595
int dataPin = 11;
byte FirstByte;
byte SecondByte;
byte ThirdByte;
byte FourthByte;
byte FifthByte;
int val;
byte serialInArray[5]; // array for storing 3 bytes as they arrive from processing
int serialCount = 0; // for counting the number of bytes received
void setup() {
//Start Serial for debuging purposes
Serial.begin(9600);
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
}
void loop() {
if (Serial.available() > 0){
serialInArray[serialCount] = Serial.read(); // read a byte sent by processing
serialCount++; // increment number of bytes received
if (serialCount > 4 ) { // when 3 bytes received
FirstByte = serialInArray[0]; // get value for Red LEDs
SecondByte = serialInArray[1]; // get value for Green LEDs
ThirdByte = serialInArray[2];
FourthByte = serialInArray[3];
FifthByte = serialInArray[4];
Serial.print(FirstByte);
Serial.print(SecondByte);
Serial.print(ThirdByte);
Serial.print(FourthByte);
Serial.print(FifthByte);
Serial.println("");
//count up routine
digitalWrite(latchPin, 0);
//count up on GREEN LEDs
//count down on RED LEDs
shiftOut(dataPin, clockPin, FirstByte);
shiftOut(dataPin, clockPin, SecondByte);
shiftOut(dataPin, clockPin, ThirdByte);
shiftOut(dataPin, clockPin, FourthByte);
shiftOut(dataPin, clockPin, FifthByte);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
serialCount = 0;
delay(20);
}
}
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut�
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
Your topic was MOVED to its current forum category as it is more suitable than the original
Do you have a question ?
I guess the question is "How to (record and play) data from shift register".
@sadk_sadk you must explain in more detail what you wish to do.
Do you want to save the state of the shift register when one or more buttons are pressed ?
If so then how long do you want to save them for and what do you want to do with them afterwards ? Does the time that the save was done or the elapsed time between saved values have any meaning ?
Nice picture of a bunch of wires connected to a bunch of circuit boards, but what relevance does this have to your question?
I might guess that you think it tells us what your circuit is, sorry it doesn't.
If you want to give us a shot at trying to guess what such an ambiguous question you asked we need to see your schematic, that is not a Fritzing physical layout but real schematic, hand drawn is fine.
Note normally shift registers are either parallel out serial in or serial in parallel out. So reading and writing to a shift register normally can't be done it is either one or the other.
The data comes from outside when pressing the button is recorded, then the computer is separated wire serial to play, duration almost five minutes
@sadk_sadk are you using some sort of computer based translator to generate your response. It looks like it to me.
What sort of data rate are you using? One second per data bit? Or 1mS per data bit?
Yes use that... 1mS per data bit, 56×56 bit per second
Not sure what the 56X56 bits are but assuming these are bits you have to store in memory that will be:-
56 X 56 = 3136 bits which in bytes is 3136 / 8 = 392 bytes per second. For five minutes is 392 * 60 * 5 = 117600 bytes of storage or about 117.6 K of storage.
It is worth noting that on an Arduino Uno the absolute maximum you have for all storage of variables, including those you need to run the stack is 2K.
So where is this extra storage going to come from?
Using SD Card, Can this be achieved
Possibly yes.
How can the record/play data from the shift register
using switches and SD card
data comes from outside Arduino when pressing the button is recorded, then the computer is separated wire serial to play, duration almost five minutes
, 56×56 bit per second
//Pin connected to ST_CP of 74HC595
int latchPin = 6;
//Pin connected to SH_CP of 74HC595
int clockPin = 13;
////Pin connected to DS of 74HC595
int dataPin = 11;
byte FirstByte;
byte SecondByte;
byte ThirdByte;
byte FourthByte;
byte FifthByte;
int val;
byte serialInArray[5]; // array for storing 3 bytes as they arrive from processing
int serialCount = 0; // for counting the number of bytes received
void setup() {
//Start Serial for debuging purposes
Serial.begin(9600);
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
}
void loop() {
if (Serial.available() > 0){
serialInArray[serialCount] = Serial.read(); // read a byte sent by processing
serialCount++; // increment number of bytes received
if (serialCount > 4 ) { // when 3 bytes received
FirstByte = serialInArray[0]; // get value for Red LEDs
SecondByte = serialInArray[1]; // get value for Green LEDs
ThirdByte = serialInArray[2];
FourthByte = serialInArray[3];
FifthByte = serialInArray[4];
Serial.print(FirstByte);
Serial.print(SecondByte);
Serial.print(ThirdByte);
Serial.print(FourthByte);
Serial.print(FifthByte);
Serial.println("");
//count up routine
digitalWrite(latchPin, 0);
//count up on GREEN LEDs
//count down on RED LEDs
shiftOut(dataPin, clockPin, FirstByte);
shiftOut(dataPin, clockPin, SecondByte);
shiftOut(dataPin, clockPin, ThirdByte);
shiftOut(dataPin, clockPin, FourthByte);
shiftOut(dataPin, clockPin, FifthByte);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
serialCount = 0;
delay(20);
}
}
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut�
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
TOPICS MERGED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.
Could you also take a few moments to [url=https://forum.arduino.cc/index.php?topic=710766.0]Learn How To Use The Forum[/url].
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
I
Can you guide me to that?
Your code seems to have no relationship with your schematic nor your stated aim. Why are you messing about with reading a serial input from processing?
stated aim in ((pink)) To make the Arduino unconnected to the computer via the serial port
Code for more than shift register The data comes
from Visual Basic via the serial port it works fine
Do you mean unconnected or do you mean connected?
I can't see any pink?
It is simple, to record every time you send something the the shift register you also store it in the SD card, along with the value given by millis.
Then to play back read from the SD card the byte and the millis value. Then wait until the time that is millis minus the millis time when you started the playback matches or is greater than the millis value you read from the SD card, then write out the byte to the shift register.
Is this just a pointless exercise given as an assignment or does it have some practical application?