学习:LED灯闪烁

 

 

const int led_id =13;
int led_state = LOW;

long previous_millis = 0;
long interval = 1000;


void setup() {
  // put your setup code here, to run once:
  pinMode(led_id,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long current_millis = millis();
  if((current_millis - previous_millis)>interval){
      previous_millis = current_millis;

      if(led_state == LOW){
        led_state = HIGH;
      }else{
        led_state = LOW;
      }
  }
  digitalWrite(led_id,led_state);

  //
}

 

 

##########################

posted @ 2025-11-21 22:16  西北逍遥  阅读(6)  评论(0)    收藏  举报