mlynch / arduino-snippets

Helpful snippets for Arudino C++ projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arduino Snippets

Library of useful C++ snippets and reusable classes I've created as I build out Arduino Uno and ESP32 projects.

Button

A simple button utility that debounces and is meant to be triggered on LOW from a pin set to INPUT_PULLUP.

// some data to send to action on press
int bData = ... 
 
void handleButton(void *data) {
  // Handle the button press
}
 
Button b(PIN, &bData, handleButton)
 
void loop() {
  b->test();
}

Seven Segment

A utility for 4-digit seven segment displays using the TM1637 Drive Chip like these

#include "SevenSegment.h"

#define CLK 2
#define DIO 3

SevenSegment segment(CLK, DIO);

void onHalfSecond() {
  segment.clockPoint();
  
  // Set the hours and minutes from a clock source
  segment.setHours(clock.getHours());
  segment.setMinutes(clock.getMinutes());
  segment.update();
}

void setup() {
  segment.init();
  
  // Some kind of trigger on ever half-second
  // to flash the segment clock point
  // Timer1.initialize(500000); //timing for 500ms
  // Timer1.attachInterrupt(onHalfSecond);
}

void loop() {
  segment.loop();
}

About

Helpful snippets for Arudino C++ projects

License:MIT License


Languages

Language:C++ 100.0%