Sketch that responds to certain commands, how is it done?

后端 未结 4 1061
执笔经年
执笔经年 2021-01-27 08:50

Alright I have a half complete Arduino sketch at the moment. Basically the sketch below will blink an LED on a kegboard-mini shield if a string of chars equals *{blink_Flow_A}*

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-27 08:54

    Perhaps something like the 'blink without delay' example in the IDE. You check the time and decide to when and how to change the LED/Digital out.

    // Variables will change:
    int ledState = LOW;             // ledState used to set the LED
    long previousMillis = 0;        // will store last time LED was updated
    
    // the follow variables is a long because the time, measured in miliseconds,
    // will quickly become a bigger number than can be stored in an int.
    long interval = 1000;           // interval at which to blink (milliseconds)
    
    void setup(){
        // Your stuff here
    }
    
    
    void loop()
    {
     // Your stuff here.
    
     // check to see if it's time to blink the LED; that is, if the 
     // difference between the current time and last time you blinked 
     // the LED is bigger than the interval at which you want to 
     // blink the LED.
     unsigned long currentMillis = millis();
    
    if(currentMillis - previousMillis > interval) {
      // save the last time you blinked the LED 
      previousMillis = currentMillis;   
    
      // if the LED is off turn it on and vice-versa:
      if (ledState == LOW)
        ledState = HIGH;
      else
        ledState = LOW;
    
      // set the LED with the ledState of the variable:
      digitalWrite(ledPin, ledState);
    }
    }
    

提交回复
热议问题