program for 4 digits 7 segments
hi, trying code program makes number 0 9999 written on 4digit 7 segments. problem when put big delay() @ end of loop can see numbers 1 one on each digit when trying reduce delay() leds on digits blink quickly. here code , pic of arduino:
code: [select]
const int verrou = 10;
const int horloge = 11;
const int data = 12;
char sens = lsbfirst;
int nombre[10] = {63, 6, 91, 79, 102, 109, 125, 7, 255, 103};
char p10[4];
const int digit[4] = {2, 3, 4, 5};
int x;
byte n;
byte p;
long temps;
byte q;
byte s;
byte d;
void setup() {
// put setup code here, run once:
pinmode(verrou, output);
pinmode(horloge, output);
pinmode(data, output);
(int = 0; < 4; i++) {
pinmode(digit[i], output);
digitalwrite(digit[i], high);
serial.begin(9600);
}
}
void decomp(void) {
if (floor(x / 1000) != 0) {
p = 4;
decomp4c();
}
if ((floor(x / 100) != 0) && (floor(x / 1000) == 0)) {
p = 3;
decomp3c();
}
if ((floor(x / 10) != 0) && (floor(x / 100) == 0) && (floor(x / 1000) == 0)) {
p = 2;
decomp2c();
}
if (floor(x / 10) == 0) {
p = 1;
decomp1c();
}
}
void decomp1c(void) {
p10[0] = x;
}
void decomp2c(void) {
float x = (float)x / 10 + 0.01;
p10[1] = floor(x);
p10[0] = (x - p10[1]) * 10;
}
void decomp3c(void) {
float x = (float)x / 10 + 0.01;
int = floor(x);
p10[0] = (x - a) * 10;
float y = (float)a / 10 + 0.01;
p10[2] = floor(y);
p10[1] = (y - p10[2]) * 10;
}
void decomp4c(void) {//2345
float x = (float)x / 10 + 0.01;//234.5
int = floor(x);//234
p10[0] = (x - a) * 10;//5
float y = (float)a / 10 + 0.01;//23.4
int b = floor(y);//23
p10[1] = (y - b) * 10; //4
float z = (float)b / 10 + 0.01; //2.3
p10[3] = floor(z);//2
p10[2] = (z - p10[3]) * 10;//3
}
void convert(void) {
(int = 0; < 4; i++) {
p10[i] = nombre[p10[i]];
}
}
void verif(void) {
if (q == 4) {
q = 0;
}
if (s == 4) {
s = 0;
}
if (s == 5) {
s = 1;
}
if (d == 4) {
d = 0;
}
if (d == 5) {
d = 1;
}
if (d == 6) {
d = 2;
}
}
void affichage(void) {
q = n+1;
s = n+2;
d = n+3;
digitalwrite(digit[n], low);
serial.println(n);
digitalwrite(digit[q], high);
verif();
serial.println(q);
digitalwrite(digit[s], high);
verif();
serial.println(s);
digitalwrite(digit[d], high);
verif();
serial.println(d);
serial.println("");
}
void loop() {
x = 2890;
decomp();
convert();
(n = 0; n < p; n++) {
affichage();
temps = millis();
while ((millis() - temps) < 4) {
digitalwrite(verrou, low);
shiftout(data, horloge, sens, p10[n]);
digitalwrite(verrou, high);
}
}
}
code: [select]
int x;
byte n;
byte p;
long temps;
byte q;
byte s;
byte d;one letter names suck, global variables. convey no useful information.
code: [select]
(int = 0; < 4; i++) {
pinmode(digit[i], output);
digitalwrite(digit[i], high);
serial.begin(9600);
}how many times need call serial.begin()?
code: [select]
while ((millis() - temps) < 4) {
digitalwrite(verrou, low);
shiftout(data, horloge, sens, p10[n]);
digitalwrite(verrou, high);
}why need done 4 milliseconds?
Arduino Forum > Using Arduino > Programming Questions > program for 4 digits 7 segments
arduino
Comments
Post a Comment