mirror of
				https://github.com/0xFEEDC0DE64/arduino-esp32.git
				synced 2025-10-31 06:01:39 +01:00 
			
		
		
		
	This is very much still work in progress and much more will change before the final 2.0.0 Some APIs have changed. New libraries have been added. LittleFS included. Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Mike Dunston <m_dunston@comcast.net> Co-authored-by: Unexpected Maker <seon@unexpectedmaker.com> Co-authored-by: Seon Rozenblum <seonr@3sprockets.com> Co-authored-by: microDev <70126934+microDev1@users.noreply.github.com> Co-authored-by: tobozo <tobozo@users.noreply.github.com> Co-authored-by: bobobo1618 <bobobo1618@users.noreply.github.com> Co-authored-by: lorol <lorolouis@gmail.com> Co-authored-by: geeksville <kevinh@geeksville.com> Co-authored-by: Limor "Ladyada" Fried <limor@ladyada.net> Co-authored-by: Sweety <switi.mhaiske@espressif.com> Co-authored-by: Loick MAHIEUX <loick111@gmail.com> Co-authored-by: Larry Bernstone <lbernstone@gmail.com> Co-authored-by: Valerii Koval <valeros@users.noreply.github.com> Co-authored-by: 快乐的我531 <2302004040@qq.com> Co-authored-by: chegewara <imperiaonline4@gmail.com> Co-authored-by: Clemens Kirchgatterer <clemens@1541.org> Co-authored-by: Aron Rubin <aronrubin@gmail.com> Co-authored-by: Pete Lewis <601236+lewispg228@users.noreply.github.com>
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include "esp_system.h"
 | |
| 
 | |
| const int button = 0;         //gpio to use to trigger delay
 | |
| const int wdtTimeout = 3000;  //time in ms to trigger the watchdog
 | |
| hw_timer_t *timer = NULL;
 | |
| 
 | |
| void ARDUINO_ISR_ATTR resetModule() {
 | |
|   ets_printf("reboot\n");
 | |
|   esp_restart();
 | |
| }
 | |
| 
 | |
| void setup() {
 | |
|   Serial.begin(115200);
 | |
|   Serial.println();
 | |
|   Serial.println("running setup");
 | |
| 
 | |
|   pinMode(button, INPUT_PULLUP);                    //init control pin
 | |
|   timer = timerBegin(0, 80, true);                  //timer 0, div 80
 | |
|   timerAttachInterrupt(timer, &resetModule, true);  //attach callback
 | |
|   timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us
 | |
|   timerAlarmEnable(timer);                          //enable interrupt
 | |
| }
 | |
| 
 | |
| void loop() {
 | |
|   Serial.println("running main loop");
 | |
| 
 | |
|   timerWrite(timer, 0); //reset timer (feed watchdog)
 | |
|   long loopTime = millis();
 | |
|   //while button is pressed, delay up to 3 seconds to trigger the timer
 | |
|   while (!digitalRead(button)) {
 | |
|     Serial.println("button pressed");
 | |
|     delay(500);
 | |
|   }
 | |
|   delay(1000); //simulate work
 | |
|   loopTime = millis() - loopTime;
 | |
|   
 | |
|   Serial.print("loop time is = ");
 | |
|   Serial.println(loopTime); //should be under 3000
 | |
| }
 |