Editing Tutorial AutoRun

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 9: Line 9:
 
* you have written a main.py that allows to select whether to boot into your code or not
 
* you have written a main.py that allows to select whether to boot into your code or not
  
== Required Module and Files ==
 
To enable autorun you have to create a file that is called 'main.py' that is in the main directory. There are different ways to do this:
 
* write the code you want to execute into the file main.py
 
* write your code as a module that can be executed by calling a function. call this function from main.
 
 
== Related Components ==
 
 
The components are related to the [[LMUBox]]. For more components, see the [[Hardware List]]. Many of the pages on actuators and sensor include additional examples.
 
 
=== Microcontroller ===
 
* [[ESP32 Web Kit]] with integrated OLED Display from Heltec
 
 
=== Sensors (and physical controllers) ===
 
* [[Switch]]
 
  
 
= Instructional Videos =
 
= Instructional Videos =
Line 32: Line 18:
  
 
<youtube>https://youtu.be/kzgUN_h1bqw</youtube>
 
<youtube>https://youtu.be/kzgUN_h1bqw</youtube>
 
 
= Examples of main.py =
 
 
== Code Example: code in main.py ==
 
<syntaxhighlight lang="python" line='line'>
 
# main.py - example how to have the code directly in the main.py file
 
# here an example for blinking an LED
 
from machine import Pin
 
from time import sleep
 
p25 = Pin(25, Pin.OUT)
 
 
while True:
 
    pin25.on()
 
    sleep(1)
 
    pin25.off()
 
    sleep(0.5)
 
</syntaxhighlight>
 
 
== Code Example: function in module and called from main.py ==
 
<syntaxhighlight lang="python" line='line'>
 
# main.py - example how to call a function (with your code) from the main.py file
 
# we assume you have a function mymain() defined in a module mycode.py
 
import mycode
 
mycode.mymain()
 
</syntaxhighlight>
 
 
== Code Example: selectively call function in module from main.py - boot switch ==
 
[[File:BootSelektor.JPG|300px]]
 
<syntaxhighlight lang="python" line='line'>
 
# main.py - example how to call a function (with your code) from the main.py file
 
# the function is only called if Pin26 is '1' (connected to 3.3V)
 
# if Pin26 is '0' the function will not be callwd
 
# we assume you have a function mymain() defined in a module mycode.py
 
import mycode
 
from machine import Pin
 
 
p26 = Pin(26, Pin.IN)
 
 
if (p26.value()==1):
 
    mycode.mymain()
 
</syntaxhighlight>
 

Please note that all contributions to Sketching with Hardware at LMU Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see My wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)