Last active
November 30, 2025 00:28
-
-
Save stonehippo/22e6ae0f8817aa2b2343766e8f25b2b5 to your computer and use it in GitHub Desktop.
Mock sensor data for CircuitPython
This file contains hidden or 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
| ''' | |
| This is a little helper for creating mock data values for a simple sensor | |
| in CircuitPython (analogous to reading from an ADC). | |
| It's not meant to be particulary accurate, just to create ranges of data | |
| that might be useful when developing. | |
| ''' | |
| from random import randint | |
| MAX_1_BIT = 2 ** 1 | |
| MAX_8_BIT = 2 ** 8 | |
| MAX_10_BIT = 2 ** 10 | |
| MAX_12_BIT = 2 ** 12 | |
| MAX_16_BIT = 2 ** 16 | |
| MAX_24_BIT = 2 ** 24 | |
| # 'read' a single value from a 'sensor' | |
| def mock_reading(max=MAX_10_BIT): | |
| return randint(0, max) | |
| # return a collection of mock data | |
| def mock_data(count=1000, max=MAX_10_BIT): | |
| return [mock_reading(max) for _ in range(0, count)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment