Skip to content

Instantly share code, notes, and snippets.

@sagiii
sagiii / pwm_reader.ino
Last active May 21, 2020 09:13
Servo PWM probe for Arduino. Assuming up edge of evey port is aligned.
const int NPIN = 2; // pin count
const int PINS[NPIN] = {2, 3}; // input pins
volatile long long t0 = 0, t[2] = {0};
void edge_function(int pin) {
byte level = digitalRead(PINS[pin]);
if(level && pin == 0) { // react to up edge of only pin 0.
t0 = micros();
Serial.print((int)t[0]);
@sagiii
sagiii / run_log.ino
Last active April 14, 2020 15:57
Arduino code idea to leave run duration log in EEPROM. (not tested)
#include <EEPROM.h>
#define CLEAR_BUTTON (2)
#define MAX_LOG_N (120)
struct run_log_t {
uint8_t last_index;
uint16_t duration[MAX_LOG_N];
};
uint8_t index;