# How to call the previous value into a new value in a separate loop?

2022-01-13T16:00:00Z

``````int pb = 0;
bool dipencet = 0 ;
int lag = 500;
int digit, i, j;

#define A  A5
#define B  A4
#define C  A3
#define D  A2
#define E  A1
#define F  A0

void setup() {
// put your setup code here, to run once:
pinMode(pb, INPUT_PULLUP); //digitalWrite(pb,HIGH);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);

for (digit = 1 ; digit < 9; digit++)
{
pinMode(digit, OUTPUT);
}
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
for (digit = 1; digit < 9 ; digit++) {
digitalWrite(digit, HIGH);
delay(lag);
digitalWrite(digit, LOW);
}
digit = i;
for (i = digit; i> 0 ; i--) {
digitalWrite(i, HIGH);
delay(lag);
digitalWrite(i, LOW);
}

}

}
``````

the initial value is the digits run to the right, if I press the push button then the digits will run to the left, if pressed again then the digits will return to the initial value, and if I press it for a long time then the digits will run to the right and left moving only at 1 digit

``````int pb = 0;
bool dipencet = 0 ;
int lag = 500;
int digit,i,j;
int count = 0;
bool mode = false;
#define A  A5
#define B  A4
#define C  A3
#define D  A2
#define E  A1
#define F  A0

void setup() {
// put your setup code here, to run once:
pinMode(pb,INPUT_PULLUP); //digitalWrite(pb,HIGH);
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
pinMode(E,OUTPUT);
pinMode(F,OUTPUT);

for (digit= 1 ; digit<9; digit++)
{
pinMode(digit,OUTPUT);
}
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(A,LOW);
digitalWrite(B,HIGH);
digitalWrite(C,HIGH);
digitalWrite(D,LOW);
digitalWrite(E,LOW);
digitalWrite(F,LOW);
for(digit = 1; digit < 9 ; digit++)
{
{
for(i = digit; i > 0 ; i--)
{
for(j = i; j<9 ; j++){
digitalWrite(j,HIGH);
delay(lag);
digitalWrite(j,LOW);
while(j ==8){
j = 0;
}
count = 0;
mode = false;
}
}
digitalWrite(i,HIGH);
delay(lag);
digitalWrite(i,LOW);
while(i == 1)
{
i = 9;
}
}
count = 1;
mode = true;
}
digitalWrite(digit,HIGH);
delay(lag);
digitalWrite(digit,LOW);
}
}
``````

it's 7 segment 8 digits

i didn't need 'G'

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.