-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python: update entropy-meter experiment
- Loading branch information
Showing
1 changed file
with
31 additions
and
10 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,21 +1,42 @@ | ||
# Imports go at the top | ||
from microbit import * | ||
|
||
dot: "tuple[int, int, int]" = (0, 0, 0) | ||
data: "tuple[int, int, int]" = (0, 0, 0) | ||
|
||
direction: float = 0.0 | ||
class EntropyMeter: | ||
"""Accidentally discovered that the accelerometer always returns data even when idle.""" | ||
|
||
def __init__(self) -> None: | ||
self.dot: "tuple[int, int, int]" = (0, 0, 0) | ||
self.data: "tuple[int, int, int]" = (0, 0, 0) | ||
|
||
self.direction: float = 0.0 | ||
|
||
def run(self) -> None: | ||
""" | ||
1. Gets "entropy" data (the accelerometer is never "idle") | ||
2. Use the data to draw a dot. | ||
""" | ||
|
||
self.data = accelerometer.get_values() | ||
print("INFO: data=" + str(self.data)) | ||
|
||
# x, y, brightness | ||
self.dot = (abs(self.data[0] % 5), abs(self.data[1] % 5), abs(self.data[2] % 10)) | ||
print("INFO: dot=" + str(self.dot)) | ||
display.set_pixel(*self.dot) | ||
|
||
|
||
print() | ||
print("Entropy Meter") | ||
print() | ||
|
||
display.on() | ||
display.clear() | ||
|
||
app: EntropyMeter = EntropyMeter() | ||
|
||
# Code in a 'while True:' loop repeats forever | ||
while True: | ||
data = accelerometer.get_values() | ||
print("INFO: data=" + str(data)) | ||
|
||
# x, y, brightness | ||
dot = (abs(data[0] % 5), abs(data[1] % 5), abs(data[2] % 10)) | ||
print("INFO: dot=" + str(dot)) | ||
display.set_pixel(*dot) | ||
app.run() | ||
|
||
sleep(1_000) |