|
楼主 |
发表于 2019-3-24 17:30
|
显示全部楼层
S型扭呀扭
[mw_shl_code=arduino,true]#include <MsTimer2.h> //定时中断的库
// 使用 74HC595
// 接 74HC595 的 ST_CP (pin 12,latch pin)
#define latchPin 5
// 接 74HC595 的 SH_CP (pin 11, clock pin)
#define clockPin 4
// 接 74HC595 的 DS (pin 14)
#define dataPin 3
#define dataPin2 9 //双色备用
byte led[8][8] ={
{0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},
{0x00,0x7E,0x00,0x00,0x00,0x00,0x7E,0x00},
{0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00},
{0x00,0x00,0x3C,0x00,0x00,0x3C,0x00,0x00},
{0x00,0x7E,0x00,0x00,0x00,0x00,0x7E,0x00},
{0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xFF},
};
byte buff[8];
uint8_t layer = 0;
unsigned int num = 0;
void ledout(){ //定时中断,扫描每一层
layer++;
if (layer ==8)
layer = 0;
outchar(layer);
}
void setup() {
// 将 latchPin, clockPin, dataPin 设置为输出
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(dataPin2, OUTPUT);
MsTimer2::set(2, ledout); // 2ms period
MsTimer2::start();
//Serial.begin(115200);
}
void loop() {
for(int i = 0;i<8;i++){ //把底层放入缓存
buff = led[7];
}
for(int i=0;i<7;i++){ //顺序下移一层
for(int j=0;j<8;j++){
led[j][7-i] = led[j][6-i];
}
}
for(int i = 0;i<8;i++){ //把缓存放入顶层
led[0] = buff;
}
delay(100);
}
void outchar(int outx){
digitalWrite(latchPin, LOW);
OUTDATA(dataPin,dataPin2, clockPin,1<<(7-outx),0); //层选中
// int m=5;
for (int m=0;m<8;m++){ //输出8个立面
OUTDATA(dataPin,dataPin2, clockPin,led[m][outx],0);
}
digitalWrite(latchPin, HIGH);
}
void OUTDATA(uint8_t x,uint8_t y, uint8_t clockp, uint8_t val, uint8_t val_2){
uint8_t i;
for (i = 0; i < 8; i++){
digitalWrite(x, (val & ( 1<< i )));
digitalWrite(y, (val_2 & (1<< i )));
digitalWrite(clockp, HIGH);
digitalWrite(clockp, LOW);
}
}[/mw_shl_code]
|
|