Pins
List of pin Python functions in the FarmBot Python library
on(pin_number)
Sets the state of the given pin to digital 1
, also known as “high” or “on”.
# Turn on the lighting peripheral
fb.on(7)
off(pin_number)
Sets the state of the given pin to digital 0
, also known as “low” or “off”.
# Turn off the lighting peripheral
fb.off(7)
read_pin(pin_number, mode=”digital”)
Reads the given pin with the read mode analog
or digital
. Defaults to digital
if no mode is given.
Calling read_pin()
does not record the reading in the API, it only reads the pin.
# Read pin 23 in digital mode
fb.read_pin(23)
# Read pin 23 in digital mode (alternative syntax)
fb.read_pin(23, "digital")
# Read pin 25 in analog mode
fb.read_pin(25, "analog")
read_sensor(sensor_name)
Reads the given sensor.
# Read the soil moisture sensor
fb.read_sensor("Soil Moisture")
Sensor ID lookups are cached. See clearing the cache.
control_peripheral(peripheral_name, value, mode=None)
Sets the state of the given peripheral.
# Turn on the LED peripheral
fb.control_peripheral("LED", value=1, mode="digital")
Peripheral ID lookups are cached. See clearing the cache.
toggle_peripheral(peripheral_name)
Toggles the state of the given peripheral between digital 1
(on) and 0
(off).
If the pin is initially set to an analog value, it will be rounded to the nearest digital value and then toggled.
# Toggle the LED peripheral
fb.toggle_peripheral("LED")
Peripheral ID lookups are cached. See clearing the cache.
write_pin(pin_number, value, mode=”digital”)
Sets a pin to a particular mode and value.
# Set pin 13 to digital mode and write a value of 1
fb.write_pin(13, value=1, mode="digital")
# Set pin 13 to analog mode and write a value of 128
fb.write_pin(13, value=128, mode="analog")
control_servo(pin, angle)
Controls a servo motor connected to the given pin by setting the angle.
pin
is typically one of the Farmduino servo pins: 4
, 5
, 6
, or 11
.
angle
must be between 0
and 180
.
# Set the servo motor connected to pin 4 to 90 degrees
fb.control_servo(4, angle=90)