Why is splitted in two devices ? because for one nano its too high load .
I think it is intended as a one-shot file write and you need to re-cycle the power to do a new write cycle.
Exactly ! the too much printing is for debugging (Serial Plotter)
ok, and that magically unnamed pins doing communication between two boards, am i right?
what you mean?
if (encoderPosition <= 0 && continue123 == 1 ) {
encoderPosition = 0;
Serial.println("ENCODER_POSTION0");
digitalWrite(5 , LOW); // << -- no name
pinMode(3 , INPUT); // << -- no name
pinMode(7, INPUT_PULLUP);// << -- no name
I'd move this whole chunk of the updateEncoder ISR into loop:
Serial.println(encoderPosition);
//Serial.println(encoderPosition);
if (encoderPosition >= 9000 && continue123 == 0 && przycisk == 1 ) {
encoderPosition = 9000;
Serial.println("ENCODER_POSTION9000");
continue123 = 1;
digitalWrite(5, HIGH);
}
if (encoderPosition <= 0 && continue123 == 1 ) {
encoderPosition = 0;
Serial.println("ENCODER_POSTION0");
digitalWrite(5, LOW);
przycisk = 0;
continue123 = 0;
SD_WRITE = 1;
}
... and carefully read the encoder, guard it with a state change detection on encoderPosition like this completely untested snippet:
noInterrupts();
int myEncoderPosition = encoderPosition;
interrupts();
static int myLastPos = -1; // remember a last reading for state change detection
if (myEncoderPosition != myLastPos) {
myLastPos = myEncoderPosition;
Serial.println(myEncoderPosition);
//Serial.println(myEncoderPosition);
if (myEncoderPosition >= 9000 && continue123 == 0 && przycisk == 1 ) {
myEncoderPosition = 9000;
Serial.println("ENCODER_POSTION9000");
continue123 = 1;
digitalWrite(5, HIGH);
}
if (myEncoderPosition <= 0 && continue123 == 1 ) {
myEncoderPosition = 0;
Serial.println("ENCODER_POSTION0");
digitalWrite(5, LOW);
przycisk = 0;
continue123 = 0;
SD_WRITE = 1;
}
}
Also use the loop's myEncoderPosition copy of in the array writing because interrupts could corrupt use of encoderPosition.
Does it take 10s to do the first +10000 steps?
I think it could be this:
interacting with:
and writing past myList2[69] after 70000ms.
Maybe try
if (przycisk == 1 && (millis() - przerwa )>= 1000){
myList[cdk] = (analogRead(A1)/20.46);
myList2[cdk] = (encoderPosition);
przerwa = millis();
if (cdk<70) cdk++; // protect against overwriting end of array.
}
Or:
if (przycisk == 1 && (millis() - przerwa )>= 1000){
myList[cdk] = (analogRead(A1)/20.46);
myList2[cdk] = (encoderPosition);
przerwa = millis();
cdk++;
if (cdk>=69) cdk = 35; // protect against overwriting end of array.
}
And instead of '70' in multiple places, you should add a const int ArraySize=70;
and use that.
Or open the file and write the data directly to the SD card during the processing and completely skip storing it in a temporary array.
thx you bro i work well