Skip to content

Commit

Permalink
python: update entropy-meter experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed May 23, 2024
1 parent 02c4979 commit ad6345f
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions python/src/entropy-meter.py
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)

0 comments on commit ad6345f

Please sign in to comment.