Код 1. без регистра
PHP код:
int gear=0;
char digit[] = {
0b11000000, //0
0b11111001, //1
0b10100100, //2
0b10110000, //3
0b10011001, //4
0b10010010 //5
};
void setup()
{
PORTD = 0x00;
DDRD = 0xFF;
PORTB=0x1F;
DDRB=0x00;
}
void loop()
{
if(digitalRead(8)==0)gear=1;
if(digitalRead(9)==0)gear=2;
if(digitalRead(10)==0)gear=3;
if(digitalRead(11)==0)gear=4;
if(digitalRead(12)==0)gear=5;
delay(80);
PORTD = digit[gear];
}
Код 2. с регистром:
PHP код:
//connected to ST_CP
int latchPin = 3;
//connected to SH_CP
int clockPin = 4;
//connected to DS
int dataPin = 2;
int gear =0;
int digit[] =
{
192, //0
249, //1
164, //2
176, //3
153, //4
146};//5
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
PORTB=0x1F;
DDRB = 0x00;
}
void loop()
{
if(digitalRead(8)==0)gear=1;
if(digitalRead(9)==0)gear=2;
if(digitalRead(10)==0)gear=3;
if(digitalRead(11)==0)gear=4;
if(digitalRead(12)==0)gear=5;
delay(80);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, digit[gear]);
digitalWrite(latchPin, HIGH);
}