This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-organized structure for autocorrect (#193)
re-structuring for auto-completion
- Loading branch information
Showing
15 changed files
with
259 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
from .shim import * | ||
from .__model.image import Image | ||
from .__model.microbit_model import __mb | ||
|
||
button_a = __mb.button_a | ||
button_b = __mb.button_b | ||
display = __mb.display | ||
|
||
|
||
def sleep(n): | ||
""" | ||
Wait for ``n`` milliseconds. One second is 1000 milliseconds, so:: | ||
microbit.sleep(1000) | ||
will pause the execution for one second. ``n`` can be an integer or | ||
a floating point number. | ||
""" | ||
__mb.sleep(n) | ||
|
||
|
||
def running_time(): | ||
""" | ||
Return the number of milliseconds since the board was switched on or | ||
restarted. | ||
""" | ||
__mb.running_time() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class Button: | ||
# The implementation is based off of https://microbit-micropython.readthedocs.io/en/v1.0.1/button.html. | ||
def __init__(self): | ||
self.__pressed = False | ||
self.__presses = 0 | ||
self.__prev_pressed = False | ||
|
||
def is_pressed(self): | ||
""" | ||
Returns ``True`` if the specified button ``button`` is currently being | ||
held down, and ``False`` otherwise. | ||
""" | ||
return self.__pressed | ||
|
||
def was_pressed(self): | ||
""" | ||
Returns ``True`` or ``False`` to indicate if the button was pressed | ||
(went from up to down) since the device started or the last time this | ||
method was called. Calling this method will clear the press state so | ||
that the button must be pressed again before this method will return | ||
``True`` again. | ||
""" | ||
res = self.__prev_pressed | ||
self.__prev_pressed = False | ||
return res | ||
|
||
def get_presses(self): | ||
""" | ||
Returns the running total of button presses, and resets this total | ||
to zero before returning. | ||
""" | ||
res = self.__presses | ||
self.__presses = 0 | ||
return res | ||
|
||
def __press_down(self): | ||
self.__pressed = True | ||
self.__prev_pressed = True | ||
self.__presses += 1 | ||
|
||
def __release(self): | ||
self.__pressed = False |
File renamed without changes.
This file contains 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
Oops, something went wrong.