# Laser Distance Ruler

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/distance_measure.jpg)

A ruler using a TOF sensor.

### Building Instructions

[Building Instructions(Right Click->Save As)](https://github.com/kittenbothk/kittenbothk/raw/master/Kits/future_inventor/instructions/pdf/laser_ruler.pdf)

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/ruler_wire.png)

### Sample Wiring Diagram

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/ruler_wire.png)

### Sample Program

#### KittenBlock Sample Program

![](https://kittenbothk-eng.readthedocs.io/en/latest/_images/ruler_code.png)

[Download Sample Program(Right Click->Save As)](https://github.com/kittenbothk/kittenbothk/raw/master/Kits/future_inventor/instructions/sb3/laser.sb3)

#### Python Sample Program

```
#/bin/python

from future import *
from sugar import *

y = 0
y1 = 0
y2 = 0
x = 0


def valmap(x, in_min, in_max, out_min, out_max):
    return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)


def baseline():
  global y,y1,y2,x

  screen.line(77,10,82,10,(0, 255, 0))
  screen.line(77,25,82,25,(0, 255, 0))
  screen.line(77,40,82,40,(0, 255, 0))
  screen.line(77,55,82,55,(0, 255, 0))
  screen.text(str('0'),63,5,1,(0, 255, 0))
  screen.text(str('30'),58,20,1,(0, 255, 0))
  screen.text(str('60'),58,35,1,(0, 255, 0))
  screen.text(str('90'),58,50,1,(0, 255, 0))
  y = (valmap(sensor.pitch(), 0, 90, 55, 10))
  screen.line(80,y,210,y,(255, 0, 0))



screen.sync = 0

while True:
  if Button("P1").value() == 0:
    screen.fill((0, 0, 0))
    baseline()
    x = TOFDistance().value()
  if x > 1000:
    screen.textCh(x,15,80,3,(0, 119, 255))
  else:
    if x < 100:
      screen.textCh(x,45,80,3,(0, 119, 255))
    else:
      screen.textCh(x,30,80,3,(0, 119, 255))
  screen.refresh()
```

[Download Sample Program(Right Click->Save As)](https://github.com/kittenbothk/kittenbothk/raw/master/Kits/future_inventor/instructions/py/laser.py)

### Program Instructions

Press the button, the Futureboard will display the distance measured.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sharinghub-eng.kittenbot.hk/educational-kit-sets/futureboard-iot-education-kit/futureboard-iot-education-kit-instructions/laser-distance-ruler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
