[go: nahoru, domu]

Skip to content

gesaleh/MicroPython-Examples

 
 

Repository files navigation

MicroPython-Examples

This repo features examples for MicroPython similar to Arduino.

###00.Basics

boot.py
Sample boot file which points to 'helloWorld.py' to run after booting. The examples in this repo will not include copies of the boot file. Please edit and include boot.py accordingly.

helloWorld.py
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 can be tested on the board without having to manually upload every time.

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

###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())

blinkToggle
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

button
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

accelerometer
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

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

###06.Clock

clock
Uses the RTC (independent Real Time Clock) in the pyboard. Prints the time and date with delay of 100 microseconds. Start time is set with variables.

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

###07.Mouse

boot.py
Sets the device as a HID when it boots.

main.py Control cursor with the pyboard's accelerometer. The USR switch is used as the button. Hold the board such that side with the microUSB port points to the direction you face.

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

###08.Sensors

HC-SR04
Prints distance values in cm and inches from two ultrasonic sensors connected to the pyboard. Uses the ultrasonic module available here and here.

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

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%