Skip to Content
Lumensalis CircuitPython framework coming soon 🎉

Units

A Unit gives meaning and scale to numeric values.

There are a lot of “numbers” moving around in LCPF. What does 5 mean? How about -0.3? Confusion arises when we don’t have a clear understanding of the units involved.

While there are limitations on how well LCPF can “enforce” proper use of units, it does try and help as much as possible.

There’s more documentation coming on Units, as this is a fairly important concept. For now, here is a quick overview of the key unit types:

NameRepresentsInPython typeDescriptionNotes
ZeroToOnescaled valuefraction of 1floata value between 0.0 and 1.0 inclusive
PlusMinusOnescaled value+/- fraction of 1floata value between -1.0 and 1.0 inclusive
TimeInNStimenanosecondsintTime in nanoseconds
TimeSpanInNStime spannanosecondsintTime span in nanoseconds
TimeInMStimemillisecondsintTime in milliseconds
TimeSpanInMStime spanmillisecondsintTime span in milliseconds
TimeInSecondstimesecondsfloatTime in seconds
TimeSpanInSecondstime spansecondsfloatTime span in seconds
DegreesPerSecondrotation speeddegrees per secondfloatrotation speed in degrees per second
Degreesangledegreesfloatangle in degrees
Millimeterslengthmillimetersfloatlength in millimeters
Voltsvoltagevoltsfloatvoltage in volts
Hertzfrequencycycles per secondfloatfrequency in cycles per second

Hopefully, most of these are fairly self explanatory, although more details will be added. The two which might not be obvious, but are very useful to understand are:

  • ZeroToOne
    • a scaled value between 0.0 and 1.0 inclusive.
    • It is often used for things like
      • brightness, where 0.0 is off and 1.0 is full brightness.
      • volume, where 0.0 is mute and 1.0 is full volume.
      • RGB color channel values
        • 0.0/0.0/0.0 is black
        • 1.0/1.0/1.0 is white
  • PlusMinusOne
    • a scaled value between -1.0 and 1.0 inclusive.
    • It is used for things like
      • speed control, where -1.0 is full reverse, 0.0 is stopped, and 1.0 is full forward.

The use of 0.0 to 1.0 or -1.0 to 1.0 is very intenional, and used to normalize values and make them easier to work with. There are many examples of various devices which typically require you to “know” about specific ranges. For example, NeoPixels typically use 0-255 for each color channel. Servo and motor controllers often use things like duty cycles and PWM frequencies which you have to take into account. The LCPF hides those details as much as possible, and the ZeroToOne/PlusMinusOne unit types are a major part of that.

Last updated on