// C++ code
//單燈右移使用 雙 for 回圈讀陣列資料表完成
void setup()
{
for(int i=2;i<=9;i++)
pinMode(i, OUTPUT);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
}
//---------------------------------------------------------
byte r2_shift[][8]={{1,1,0,0,0,0,0,0},// r_shift[7][6]
{0,1,1,0,0,0,0,0},
{0,0,1,1,0,0,0,0},
{0,0,0,1,1,0,0,0},
{0,0,0,0,1,1,0,0},
{0,0,0,0,0,1,1,0},
{0,0,0,0,0,0,1,1},
{0,0,0,0,0,0,0,0}};
byte r2_shiftx[]={0xc0,0x60,0x30,0x18,0x0c,0x06,0x03,0x00};
//----------------------------------------------------------
void r2shift()
{
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
if(r2_shift[i][j])digitalWrite(j+2, HIGH);
else digitalWrite(j+2, LOW);
delay(500); // Wait for 1000 millisecond(s)
}
}
//----------------------------------------------------------
byte r_shift[][8]={{1,0,0,0,0,0,0,0},// r_shift[7][6]
{0,1,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0}};
byte r_shiftx[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00};
byte r_shiftb[]={B10000000,B01000000,B00100000,B00010000,
B00001000,B00000100,B00000010,B00000001,
B00000000};
//----------------------------------------------------------
void rshiftx()
{
for(int i=0;i<9;i++)
{
for(int j=0;j<8;j++)
if(bitRead(r_shiftb[i],7-j))digitalWrite(j+2, HIGH);
else digitalWrite(j+2, LOW);
delay(200); // Wait for 1000 millisecond(s)
}
}
//---------------------------------
int count=0;
unsigned long datatimes=0;
#define SH_CP 7
#define ST_CP 6
#define DATA_SER 5
int key=0;
void rshift595()
{
}
void r2shift595()
{
if(millis()-datatimes >=350)
{
datatimes=millis();
count=(1+count)%9;
}
}
//-------------------------------------------------
void rshift()
{
for(int i=0;i<9;i++)
{
for(int j=0;j<8;j++)
if(r_shift[i][j])digitalWrite(j+2, HIGH);
else digitalWrite(j+2, LOW);
delay(500); // Wait for 1000 millisecond(s)
}
}
//-----------------------------------------------------------
byte r_on[][8]= {{1,0,0,0,0,0,0,0},
{1,1,0,0,0,0,0,0},
{1,1,1,0,0,0,0,0},
{1,1,1,1,0,0,0,0},
{1,1,1,1,1,0,0,0},
{1,1,1,1,1,1,0,0},
{1,1,1,1,1,1,1,0},
{1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0}};
//----------------------------------------------------------
void ron()
{
for(int i=0;i<9;i++)
{
for(int j=0;j<8;j++)
if(r_on[i][j])digitalWrite(j+2, HIGH);
else digitalWrite(j+2, LOW);
delay(500); // Wait for 1000 millisecond(s)
}
}
int fun=0;
//----------------------------------------------------------
void loop()
{
if (digitalRead(10)==0 ) fun=(fun+1)%3;
if(fun==1)
{
digitalWrite(ST_CP, LOW);
shiftOut(DATA_SER,SH_CP,LSBFIRST,r2_shiftx[count]);
digitalWrite(ST_CP, HIGH);
if(millis()-datatimes >=350)
{
datatimes=millis();
count=(1+count)%8;
}
}
// ron();
// r2shift();
}