axial

package
v0.0.0-...-21f78e4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Axial1Band int = iota + 1 // 0 Ω resistors are single black band
	Axial3Band int = iota + 2
	Axial4Band
	Axial5Band
	Axial6Band
)
View Source
const (
	Invalid          = -1
	DefaultTolerance = 20
)

Variables

View Source
var (
	ErrBandCodeLength = errors.New("invalid length")
	ErrBandColor      = errors.New("unknown color")
	ErrBandPosition   = errors.New("invalid color at position")
)

Functions

func Tokenize

func Tokenize(s string) []string

Types

type Band

type Band struct {
	Code string `json:"code"`
	// SignificantFigures is a digit of the resistor value in ohms.
	SigFig float64 `json:"sig_fig,omitempty"`
	// Multiplier is the multiplier of the resistor value.
	Multiplier float64 `json:"multiplier,omitempty"`
	// Tolerance is the tolerance of the resistor value in percentage.
	Tolerance float64 `json:"tolerance,omitempty"`
	// TCR is the temperature coefficient of resistance in ppm/K.
	TCR int `json:"tcr,omitempty"`
}

func ColorToBand

func ColorToBand(b BandColor) Band

ColorToBand returns the Band struct for the given BandColor.

type BandColor

type BandColor int
const (
	None BandColor = iota
	Black
	Brown
	Red
	Orange
	Yellow
	Green
	Blue
	Violet
	Grey
	White
	Gold
	Silver
	Pink
)

func GetColor

func GetColor(s string) BandColor

type Resistor

type Resistor struct {
	// IsReversed from input order.
	IsReversed bool `json:"reversed"`
	// Bands is the color bands on the resistor.
	Bands []Band `json:"bands"`
}

Resistor is an axial resistor with color bands to represent its value.

func New

func New(ss ...string) (*Resistor, error)

func (Resistor) TCR

func (r Resistor) TCR() int

TCR returns the temperature coefficient of resistance in ppm/K.

func (Resistor) Tolerance

func (r Resistor) Tolerance() float64

Tolerance of the resistor value as ±%.

func (Resistor) Type

func (r Resistor) Type() resistor.Marking

func (Resistor) Validate

func (r Resistor) Validate() error

Validate checks if the band code is valid.

func (Resistor) Value

func (r Resistor) Value() (float64, error)

Value calculates the resistance of the band code in ohms.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL