Hey everyone - thanks for the feedback and watching my video 
@brent113 @ITmaze my current ESP 32 code is pretty rough around the edges but I’m happy to share ( see end of this msg )
The hardware you can buy here ( those are affiliate links that buys me a coffee for every 10 pcs bought haha - go directly to Aliexpress if you prefer non affiliate - no worries
)
AliExpress.com Product - M5Stack 2020 New Arrival Official ATOM Lite ESP32
…and you also need one of these ( buy a few in case you break one - they’re cheap )
AliExpress.com Product - A tracking module tracking sensor infrared reflective photoelectric switch TCRT5000
Current version is listening through the dev UI via USB.
Current code as follows…
#include <Arduino.h>
// External library: JC_Button
#include <JC_Button.h>
// External library: FastLED
#include <FastLED.h>
// Atom button + led
// HW: Pin assignments
const byte PIN_BUTTON = 39; // M5Stack Atom Lite: internal button
const byte PIN_LEDATOM = 27; // M5Stack Atom Lite: internal Neopixel LED
const byte PIN_GROVE_YELLOW = 32; // M5Stack Atom Lite: grove port, yellow cable
// Internal button
Button Btn(PIN_BUTTON);
// Internal LED controller
CRGB ledAtom[1];
// Brightness factor for LED
uint8_t brightness = 255;
// tacos
// -------------------------------
hw_timer_t * timer0 = NULL;
hw_timer_t * timer1 = NULL;
portMUX_TYPE timerMux0 = portMUX_INITIALIZER_UNLOCKED;
portMUX_TYPE timerMux1 = portMUX_INITIALIZER_UNLOCKED;
volatile uint32_t deBounce = 10;
volatile uint32_t deCnt = deBounce;
volatile uint32_t cnt = 0;
volatile uint32_t resCnt = 0;
volatile boolean isCnt = false;
void IRAM_ATTR onTimer0(){
// Critical Code here
portENTER_CRITICAL_ISR(&timerMux0);
//oddcode here
resCnt++;
deCnt--;
if ( deCnt < 2 ) { deCnt=1; if (!isCnt) if (digitalRead(23)) { cnt++; isCnt = true; deCnt = deBounce; } }
if ( deCnt < 2 ) { deCnt=1; if (!digitalRead(23)) { isCnt = false ; deCnt = deBounce; } }
portEXIT_CRITICAL_ISR(&timerMux0);
}
void IRAM_ATTR onTimer1(){
// Critical Code here
portENTER_CRITICAL_ISR(&timerMux1);
//oddcode here
Serial.print(" resolution/s "+String(resCnt)+" max_count/s "+String(resCnt/(deBounce*2))+" - ");
Serial.print("RPM ");
Serial.println(cnt*60.00);
cnt=0;
resCnt=0;
portEXIT_CRITICAL_ISR(&timerMux1);
}
void setup() {
Serial.begin(1500000);
while (!Serial);
Serial.println("Reboot");
// GPIO pins
pinMode(33,INPUT); //A0
pinMode(23,INPUT); //D0
Serial.println("Pins set");
delay (1000);
Serial.println("start timer 0");
timer0 = timerBegin(0, 20, true); // timer 0, MWDT clock period = 12.5 ns * TIMGn_Tx_WDT_CLK_PRESCALE -> 12.5 ns * 80 -> 1000 ns = 1 us, countUp
timerAttachInterrupt(timer0, &onTimer0, true); // edge (not level) triggered
timerAlarmWrite(timer0, 10, true); // 1000000 * 1 us = 1 s, autoreload true
Serial.println("start timer 1");
timer1 = timerBegin(1, 80, true); // timer 1, MWDT clock period = 12.5 ns * TIMGn_Tx_WDT_CLK_PRESCALE -> 12.5 ns * 80 -> 1000 ns = 1 us, countUp
timerAttachInterrupt(timer1, &onTimer1, true); // edge (not level) triggered
timerAlarmWrite(timer1, 1000000, true); // 1000000 * 1 us = 1 s, autoreload true
// enable the timer alarms
timerAlarmEnable(timer0); // enable
timerAlarmEnable(timer1); // enable
}
void loop() {
vTaskDelay(portMAX_DELAY); // wait as much as possible ...
/*
// Read the button state
Btn.read();
if (Btn.wasReleased()) {
ledAtom[0].setRGB(255, 255, 255);
FastLED.show();
delay(60);
ledAtom[0].setRGB(0, 10, 0);
FastLED.show();
Serial.println(" YAY ! ");
}
if (Btn.pressedFor(1000)) {
ledAtom[0].setRGB(20, 0, 0);
FastLED.show();
delay(40);
ledAtom[0].setRGB(0, 10, 0);
FastLED.show();
delay(40);
Serial.println(" HIT ! ");
}
*/
}
…and here’s the platformio.ini file
[platformio]
default_envs =
pico32
description =
[env:pico32]
platform = espressif32
board = pico32
framework = arduino
upload_speed = 1500000
lib_deps =
JC_Button
FastLED
khoih-prog/ESP32TimerInterrupt @ ^1.0.3
monitor_speed = 1500000