ADC Read
Posted: Wed Nov 02, 2016 3:09 pm
This is my first post, so please forgive improper format if there is indeed any.
Question:
I would like to request an understanding, primarily in my coding format, for a Light Dependent Resistor(LDR, or any other value driven component) connected to X19 that will ultimately return a value. With this being said, there will obviously be a Max and Min value written into the code allowing me to Pull High, or Pull Low for instance X1.
How would I be able to continuously check the value of X19 ADC and compare my Max and Min values, and when they are satisfied, produce a result through an output Pin?
Here is an example of the code that I have been working with:
import pyb
from pyb import Timer
servo1 = pyb.Servo(1)
min_val = 90
max_val = 150
adc = pyb.ADC(pyb.Pin.board.X19)
tim = pyb.Timer(6, freq=10)
buf = bytearray(10)
bval = adc.read_timed(buf, tim)
if bval >= max_val:
servo1.speed(100) # or for example: pyb.Pin('X1', pyb.Pin.OUT_PP.high()
elif bval <= min_val:
servo1.speed(0) # or for example: pyb.Pin('X1', pyb.Pin.OUT_PP.high()
Thank you for any help received...
Question:
I would like to request an understanding, primarily in my coding format, for a Light Dependent Resistor(LDR, or any other value driven component) connected to X19 that will ultimately return a value. With this being said, there will obviously be a Max and Min value written into the code allowing me to Pull High, or Pull Low for instance X1.
How would I be able to continuously check the value of X19 ADC and compare my Max and Min values, and when they are satisfied, produce a result through an output Pin?
Here is an example of the code that I have been working with:
import pyb
from pyb import Timer
servo1 = pyb.Servo(1)
min_val = 90
max_val = 150
adc = pyb.ADC(pyb.Pin.board.X19)
tim = pyb.Timer(6, freq=10)
buf = bytearray(10)
bval = adc.read_timed(buf, tim)
if bval >= max_val:
servo1.speed(100) # or for example: pyb.Pin('X1', pyb.Pin.OUT_PP.high()
elif bval <= min_val:
servo1.speed(0) # or for example: pyb.Pin('X1', pyb.Pin.OUT_PP.high()
Thank you for any help received...