Skip to content

chinadsf/MicroPython-Examples

 
 

Repository files navigation

MicroPython-Examples

####NOTE: THIS REPOSITORY HAS RECENTLY BEEN UPDATED AND THE CHANGES HAVEN'T BEEN UPDATED IN THIS FILE YET

This repo features examples for MicroPython similar to Arduino.

###00.Basics

BareMinimum
A template that serves as a starting point

HelloWorld
Turns on LED 4 (the blue LED).

REPL
REPL stands for Read-Eval-Print-Loop.
Very important and highly useful feature that allows easy debugging and quick learning.
All examples could be tested on the board without having to manually upload every time.

RunForever
A simple while True loop that mimicks Arduino's loop() at a very simple level

====================

###01.LEDs

Blink
Replicates Arduino's Blink sketch exactly (uses .on() and .off() and loops)

BlinkWithoutDelay
Replicates Arduino's BlinkWithoutDelay sketch (uses .toggle() and .millis())

BlinkWithToggle
Same as Blink, but uses .toggle()

Fade
Similar to Arduino's Fade sketch

Heartbeat
Something more interesting that simple blinks

HeartbeatFade
Similar to previous 'Heartbeat' script, but fades the light in and out instead of just switching on and off

====================

###02.Inputs

SimpleButton
Pull down button that toggles an LED

Potentiometer
Simple analog input that controls an LED's intensity

SwitchObject
Simple demo of the Switch object that can control the inbuilt USR button on the pyboard

SwitchCallback
Example of the Switch.callback function (uses interrupts)

====================

###03.Pins

PinsBasicOutput
Example of using on of the pins to control an output (LED, motor, buzzer, relay, et al)

====================

###04.Accelerometer

AccelerometerControlLED
Controls blink speed of an LED using the accelerometer's value along the X axis
This script also features a custom remap() function that remaps a value to different bounds/range

AccelerometerTest
Prints the x,y,z values of the accelerometer every second (REPL required)

====================

###05.Servos

ServoSetAngle
Example of setting a servo's angle, and animating it over time

ServoGetAngle
Generates a random number roughly between -90 and 90, and sets it as the servo's angle. The servo's angle is then obtained from the object

====================

Contributions include code from:
Mithru Vigneshwara
Dave Hylands

About

Examples for MicroPython

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%