All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kjkoster.wedo.bricks.Distance Maven / Gradle / Ivy

package org.kjkoster.wedo.bricks;

import lombok.Value;

/**
 * The representation of a single sample from a distance sensor.
 * 
 * @author Kees Jan Koster <[email protected]>
 */
@Value
public class Distance {
    private final int value;

    /**
     * Create a new distance sensor sample.
     * 
     * @param value
     *            The raw distance sensor value.
     */
    public Distance(final int value) {
        this.value = (value & 0xff);
    }

    /**
     * Return the distance in centimetres (approximately).
     * 
     * @return The distance in centimetres.
     */
    public int getCm() {
        return (int) ((20.0 / 145.0) * (value - 69));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy