利用74HC595实现的流水灯 Arduino

int big = 2;
int push = 3;
int datain = 4;

void setup()
{
  Serial.begin(9600);
  pinMode(big, OUTPUT);
  pinMode(push, OUTPUT);
  pinMode(datain, OUTPUT);
}

void loop()
{
  int num=1;
  for (int i = 0; i < 8; i++)
  {
    Serial.println("kaishi");
    digitalWrite(big, LOW);
    int data = num;
    //data分别为 1 2 4 8 16 
    //转换为二进制后分别取出每一位的值并写入到寄存器中
    for (int j = 0; j < 8; j++) 
    {
      digitalWrite(push, LOW);
      digitalWrite(datain, data & 1);
      data = data >> 1;
      digitalWrite(push, HIGH);
    }
    digitalWrite(big, HIGH);
    num = num<<1;
    delay(1000);
  }
}

原理图

电路图

posted @ 2020-06-17 01:17  chilkings  阅读(1275)  评论(0编辑  收藏  举报