Helpful code snippets for Arduino

If you program microcontrollers probably find yourself writing same functions over and over again. If you are smart enough, you simply write generalized functions that may be reused in other projects. But in many cases it happens that we write and forget. Here are several simple code snippets that may be useful in some cases. Some of the mare written by Rob Faludi with addition by Alasdair Allan.

void blinkLED(byte targetPin, int numBlinks, int blinkRate) {
  for (int i=0; i < numBlinks; i++) {
    digitalWrite(targetPin, HIGH);   
    delay(blinkRate);                
    digitalWrite(targetPin, LOW);   
    delay(blinkRate);
  }
}

The code snippets include blinking LED with predefined rate and duration, sounding buzzer at desired frequency and duration, checking free RAM, connecting to WiFi and working with EEPROM. Not much actually, but you are free to build up your own database and probably share with others.

[..Source link..]

Bookmark the permalink.

Leave a Reply