Skip to content

Commit

Permalink
Fully removed loop logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sjefferson99 committed Apr 26, 2024
1 parent 3ee0f57 commit 9d48100
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions enviro/boards/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,20 @@ def wind_direction():
# you read during transition between two values it can glitch
# fixes https://github.com/pimoroni/enviro/issues/20
voltage = 0.0
loop = 0
debug = []
while True:
value = wind_direction_pin.read_voltage()

closest_index = -1
closest_value = float('inf')

for i in range(16):
distance = abs(ADC_TO_DEGREES[i] - value)
if distance < closest_value:
closest_value = distance
closest_index = i

value = wind_direction_pin.read_voltage()

resistance = (voltage * 10000) / (3.3 - voltage)
logging.info(f"> wind direction stats - voltage: {value}, resistance: {resistance}, closest value: {closest_value}, closest index: {closest_index}, loops: {loop}")
closest_index = -1
closest_value = float('inf')

if True: #Test not waitng for two identical readings in a row
# if last_index == closest_index:
break
for i in range(16):
distance = abs(ADC_TO_DEGREES[i] - value)
if distance < closest_value:
closest_value = distance
closest_index = i

last_index = closest_index
loop += 1
resistance = (voltage * 10000) / (3.3 - voltage)
logging.info(f"> wind direction stats - voltage: {value}, resistance: {resistance}, closest value: {closest_value}, closest index: {closest_index}")

wind_direction = closest_index * 22.5

Expand Down

0 comments on commit 9d48100

Please sign in to comment.