Last active
          October 30, 2023 20:22 
        
      - 
      
- 
        Save anecdata/7470f87e18cb5543e47ceda647ab5699 to your computer and use it in GitHub Desktop. 
    CircuitPython reset to RunMode from REPL (interactive)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # SPDX-FileCopyrightText: 2023 anecdata | |
| # | |
| # SPDX-License-Identifier: MIT | |
| import microcontroller | |
| import sys | |
| mode = {"0": microcontroller.RunMode.NORMAL, | |
| "1": microcontroller.RunMode.SAFE_MODE, | |
| "2": microcontroller.RunMode.UF2, | |
| "3": microcontroller.RunMode.BOOTLOADER,} | |
| for key in sorted(mode): | |
| print(f"{key} {mode[key]}") | |
| print("press 0-3 to select RunMode, or any other key to exit to REPL...") | |
| press = sys.stdin.read(1) | |
| if press in mode: | |
| print("Resetting...") | |
| microcontroller.on_next_reset(mode[press]) | |
| microcontroller.reset() | |
| print("No reset.") | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment