<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[M5.Axp.ScreenBreath() hangs when used in interrupt]]></title><description><![CDATA[<p dir="auto">It seems that M5.Axp.ScreenBreath() hangs when it is used in a interrupt.<br />
The demo below should turn off the screen after a timer delay and turn it back on when the button is pressed. Run it in Arduino IDE.<br />
On my system, this program crashes with a watchdog timeout during i2c operation. See it in serial log.</p>
<pre><code>#include &lt;M5StickC.h&gt;
#define BUTTON_MAIN 37  //The main button pin number
#define SCREEN_TIMEOUT 10 //Screen-off timeout in seconds
hw_timer_t *timer;  //Screen-off timer

void IRAM_ATTR onButton() { //Interrupt on button press =&gt; turn on the screen
 detachInterrupt(BUTTON_MAIN); //Ignore more button presses
 M5.Axp.ScreenBreath(10); //Set screen light ON
 timerAlarmEnable(timer); //Start timer for screen-off delay
}

void IRAM_ATTR onTimer(){  //Interrupt on timer =&gt; turn off the screen
 timerAlarmDisable(timer); //Stop the timer.
 M5.Axp.ScreenBreath(0); //Set screen light OFF
 attachInterrupt(BUTTON_MAIN,onButton,FALLING); //Attach interrupt on button press =&gt; turn on the screen
}

void setup() {
M5.begin(); //Init M5. Start with screen ON.
M5.Lcd.fillScreen(YELLOW); //Make screen yellow
pinMode(BUTTON_MAIN, INPUT_PULLUP); //Button GPIO set as input, pull-up enabled
timer=timerBegin(1,40000,true); //Init screen light timer, divisor 40000 =&gt; 0.5ms steps
timerAttachInterrupt(timer,&amp;onTimer,true);  //Set screen light timer interrupt function
timerAlarmWrite(timer,SCREEN_TIMEOUT*2000,true); //Set interrupt to turn off screen after X timer steps of 0.5ms each.
timerAlarmEnable(timer); //Start timer for screen-off delay
}

void loop() {
  //No code here.
}
</code></pre>
]]></description><link>https://community.m5stack.com/topic/2392/m5-axp-screenbreath-hangs-when-used-in-interrupt</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 06:21:27 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2392.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Oct 2020 19:19:42 GMT</pubDate><ttl>60</ttl></channel></rss>