کد:
byte numbers[10] = {
0b00111111, //0
0b00000110, //1
0b01011011, //2
0b01001111, //3
0b01100110, //4
0b01101101, //5
0b01111101, //6
0b00000111, //7
0b01111111, //8
0b01101111 //9
};
byte numberstow[10] = {
0b11000000, //0
0b11111001, //1
0b10100100, //2
0b10110000, //3
0b10011001, //4
0b10010010, //5
0b10000010, //6
0b11111000, //7
0b10000000, //8
0b01101111 //9
};
byte string[10] = {
0b01110111, //A 0
0b01111100, //B 1
0b00111001, //C 2
0b01011110, //D 3
0b01111001, //E 4
0b01110001, //F 5
0b00111101, //G 6
0b01110110, //H 7
0b00111000, //L 8
0b00111111, //O 9
};
int i;
void setup() {
Serial.begin(9600);
//Clock
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(53, OUTPUT);
pinMode(49, OUTPUT);
pinMode(51, OUTPUT);
pinMode(23 , OUTPUT);
pinMode(15, OUTPUT);
pinMode(14, OUTPUT);
pinMode(50, OUTPUT);
pinMode(52, OUTPUT);
pinMode(48, OUTPUT);
pinMode(47, OUTPUT);
pinMode(43, OUTPUT);
pinMode(45, OUTPUT);
pinMode(46, OUTPUT);
pinMode(42, OUTPUT);
pinMode(44, OUTPUT);
pinMode(41, OUTPUT);
pinMode(39, OUTPUT);
pinMode(37, OUTPUT);
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(40, OUTPUT);
pinMode(36, OUTPUT);
pinMode(38, OUTPUT);
pinMode(35, OUTPUT);
pinMode(31, OUTPUT);
pinMode(33, OUTPUT);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(49, OUTPUT);
pinMode(51, OUTPUT);
pinMode(53, OUTPUT);
pinMode(49, OUTPUT);
pinMode(20, OUTPUT);
pinMode(21, OUTPUT);
printNumber("8903",8,34,32,304);
printNumber("00000000",8,11,13,12);
printNumber("00000000",8,35,31,33);
delay(2000);
}
void loop() {
//clock
printNumber("36523659",8,22,23,24);
//date
printData("12345678",8,49,51,53);
//other
printNumber("12345678",8,34,32,30);
printNumber("12345678",8,19,20,21);
printNumber("12345678",8,23,15,14);
printNumber("12345678",8,52,48,50);
printNumber("12345678",8,47,43,45);
printNumber("12345678",8,46,42,44);
printNumber("12345678",8,41,37,39);
printNumber("12345678",8,11,13,12);
printNumber("12345678",8,40,36,38);
printNumber("12345678",8,35,31,33);
printNumber("12345678",8,2,4,3);
printNumber("12345678",8,8,10,9);
printNumber("12345678",8,5,7,6);
delay(10000);
}
void printNumber(String number, int digit, int Dc, int Latch, int clockpin)
{
digitalWrite(Latch, LOW);
for (int i = digit; i > 0; i--) {
String NumbersOnetoOne = number.substring(i - 1, i);
int numarrat = NumbersOnetoOne.toInt();
Serial.println(numarrat);
shiftOut(Dc, clockpin, MSBFIRST, ~numbers[numarrat]);
}
delay(100);
digitalWrite(Latch, HIGH);
}
void printData(String number, int digit, int Dc, int Latch, int clockpin)
{
digitalWrite(Latch, LOW);
for (int i = digit; i > 0; i--) {
String NumbersOnetoOne = number.substring(i - 1, i);
int numarrat = NumbersOnetoOne.toInt();
Serial.println(numarrat);
shiftOut(Dc, clockpin, MSBFIRST, ~numberstow[numarrat]);
}
delay(100);
digitalWrite(Latch, HIGH);
}
void printString(String string, int digit, int Dc, int Latch, int clockpin)
{
digitalWrite(Latch, LOW);
for (int i = digit; i > 0; i--) {
String NumbersOnetoOne = string.substring(i - 1, i);
int numarrat = NumbersOnetoOne.toInt();
Serial.println(numarrat);
shiftOut(Dc, clockpin, MSBFIRST, ~string[numarrat]);
}
digitalWrite(Latch, HIGH);
}