Advertisement
lucasmcg

Analog in test circuit python

Sep 28th, 2021
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. """CircuitPython Essentials Analog In example"""
  2. import time
  3. import board
  4. from analogio import AnalogIn
  5. from digitalio import DigitalInOut, Direction
  6.  
  7. led = DigitalInOut(board.LED)
  8. led.direction = Direction.OUTPUT
  9. analog_in = AnalogIn(board.A1)
  10.  
  11. def get_voltage(pin):
  12.     return (pin.value * 3.3) / 65536
  13.    
  14. while True:
  15.     print(get_voltage(analog_in))
  16.     val = get_voltage(analog_in)
  17.     if val >= 1.5: # Greater than 1.5 volts
  18.         led.value = True
  19.     else:
  20.         led.value = False
  21.        
  22.     time.sleep(1.0)
  23.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement