GMTROM/Archiv/bin_string_print_console.py

23 lines
846 B
Python
Raw Normal View History

2023-06-13 09:12:10 +02:00
import time
import random
import Adafruit_ADS1x15
import RPi.GPIO as GPIO
adc = Adafruit_ADS1x15.ADS1115()
GAIN = 1
adc.start_adc_difference(0, gain=GAIN, data_rate=860)
bin_string = "" # Initialize binary string
while True:
for i in range(32): # Loop 32 times to generate 32-bit binary number
value = adc.get_last_result() # Read last conversion result
lsb = value & 0b00000001 # Extract LSB
bin_string += str(lsb) # Add LSB to binary string
bin_string = bin_string[-32:] # Keep only last 32 bits of binary string
bin_string = bin_string.zfill(32) # Pad binary string with leading zeros to ensure it is 32 bits long
print(bin_string) # Print binary string
bin_string = "" # Reset binary string back to empty string
# No need to delay, as we're using the built-in oscillator for noise