Jelenleg ez van:
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int D1=13;
int D2=9;
int D3=10;
int D4=A5;
int num =0;
int x=0;
int y=0;
int z=0;
int w=0;
int speed =3000;
unsigned long previousMillis = 0;
// a,b,c,d,e,f,g
int num_array[10][7] = { { 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,1,0,1,1 }}; // 9
//function header
void Num_Write(int);
void setup()
{
Serial.begin(9600);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
//pinMode (A5,OUTPUT);
//pinMode(12,INPUT_PULLUP);
}
void loop()
{
unsigned long currentMillis = millis();
//speed= analogRead(A4);
//speed = map(speed, 0, 1023, 10, 1000);
x = num ;
y = num/10;
z= num/100;
w= num/1000;
Serial.print(speed);
while (currentMillis - previousMillis < speed)
{
currentMillis = millis();
Num_Write(x);
digitalWrite(D1,LOW);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);
delay(8);
Num_Write(y);
digitalWrite(D1,HIGH);
digitalWrite(D2,LOW);
digitalWrite(D3,HIGH);
delay(8);
Num_Write(z);
digitalWrite(D1,HIGH);
digitalWrite(D2,HIGH);
digitalWrite(D3,LOW);
delay(8);
//Num_Write(w);
//digitalWrite(D1,HIGH);
//digitalWrite(D2,HIGH);
//digitalWrite(D3,LOW);
//delay(8);
}
if (currentMillis - previousMillis >= speed)
previousMillis = currentMillis;
Serial.print ("X= ");
Serial.println (x);
Serial.print ("Y= ");
Serial.println (y);
Serial.print ("Z= ");
Serial.println (z);
Serial.print ("Speed= ");
Serial.println (speed);
if(digitalRead(A0))
{
num--;
if(num ==10000)
num=0;
}
else
{
num++;
if(num <0)
num=999;
}
}
// this functions writes values to the sev seg pins
void Num_Write(int number)
{
int pin= 2;
for (int j=0; j < 7; j++) {
digitalWrite(pin, num_array[number][j]);
pin++;
}
}