03-22-2023, 01:05 AM
Code:
/*
KC868-256 press button S2,all leds will on one by one;
release the button,all leds will off one by one;
*/
int latchPin = 4;
int clockPin = 16;
int dataPin = 5;
int button =0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(button, INPUT);
}
void loop()
{
if(digitalRead(button)==LOW){
digitalWrite(dataPin,HIGH);
delay(10);
digitalWrite(clockPin,LOW);
delay(10);
digitalWrite(clockPin,HIGH);
delay(10);
digitalWrite(latchPin, LOW);
delay(10);
digitalWrite(latchPin, HIGH);
delay(100);
}
else {
digitalWrite(dataPin,LOW);
delay(10);
digitalWrite(clockPin,LOW);
delay(10);
digitalWrite(clockPin,HIGH);
delay(10);
digitalWrite(latchPin, LOW);
delay(10);
digitalWrite(latchPin, HIGH);
delay(100);
}
}