system
1
Hi all, I want to write a data to a memory with different addresses. From B00000000 to B11111111 in order.
How can I use portd to change the address with every 50ms? or other way ?
If I manually write PORTD from 00000000 to 11111111, it will take 2 days to be done, and I can not do any thing during the delay because I need
to read the data back from different addresses after writing.
Do you have any idea? Thanks
void setup {
DDRD = B11111111;
}
void loop{
PORTD = B00000000;
delay(50); // ???
PORTD = B00000001;
.
.
.
.
PORTD = B11111111;
}
Arrch
2
I'm not sure where this "2 days" comes into play; incrementing PORTD every 50 mS will take about 13 seconds to complete.
Start with the Blink Without Delay example. Every time the if statement fires, increment a variable and assign the value of the variable to PORTD.
system
3
Thanks, but how to increment the portd value in the loop ?
if(currentMillis - previousMillis > 50) {
previousMillis = currentMillis;
PORTD = ??
}
Arrch
4
doaway:
Thanks, but how to increment the portd value in the loop ?
if(currentMillis - previousMillis > 50) {
previousMillis = currentMillis;
PORTD = ??
}
How do you normally increment a variable?
system
5
Arrch:
doaway:
Thanks, but how to increment the portd value in the loop ?
if(currentMillis - previousMillis > 50) {
previousMillis = currentMillis;
PORTD = ??
}
How do you normally increment a variable?
i = i +1 , but the number is a binary number not a integer. how to increment a binary number ?
byte i;
i=i+1;
PORTD = i;
if (i==255){i=0;}
system
7
CrossRoads:
if (i==255){i=0;}
Why not let it overflow back to 0 on its own? That code will also skip 0, unless that's what you want.
I guess rollover would work too.
\
system
9
CrossRoads:
byte i;
i=i+1;
PORTD = i;
if (i==255){i=0;}
Thanks, if I want the program stop when PORTD = B11111111, do not what it run over and over, because I need to println data.
if (i==255){
Serial.println (whatever);
}