# Safe

Use the potentiometer to select digits and enter the password to open the safe. If the safe is cracked open, the system will sound an alarm.

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

### Building Instructions

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

### Sample Wiring Diagram

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

### KittenBlock Sample Program

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

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

### Python Sample Program

```
#/bin/python

from time import sleep
from future import *
from sugar import *
import robotbit

lock_password = 0
curr_password = 0
curr_digit = 0
x = 0
y = 0
authorize = 0
digit = 0


def activate():
  global lock_password,curr_password,curr_digit,x,y,authorize,digit

  if Button("P1").value() == 0:
    sleep(0.2)
    enterPW()



def break_in():
  global lock_password,curr_password,curr_digit,x,y,authorize,digit

  if not Hall("P2").value() == 0:
    while not Hall("P2").value() == 0:
      neopix.setColorAll((255, 0, 0))
      buzzer.melody(NOTICE)
      sleep(2)
    neopix.setColorAll((0,0,0))



def enterPW():
  global lock_password,curr_password,curr_digit,x,y,authorize,digit

  while not (len(curr_password) == len(str(lock_password))):
    screen.fill((0, 0, 0))
    screen.text(str(str(curr_password)+str(curr_digit)),30,55,3,(0, 119, 255))
    screen.refresh()
    curr_digit = (round(valmap(Angle("P0").value(), 0, 4095, 0, 9)))
    if Button("P1").value() == 0:
      curr_password = (str(curr_password)+str(curr_digit))
      digit += 1
      sleep(0.2)
    break_in()
  test()



def init():
  global lock_password,curr_password,curr_digit,x,y,authorize,digit

  robot.geekServo2kg(1, 0)
  neopix.setColorAll((0,0,0))
  screen.clear()
  lock_password = (str(2021))
  curr_password = ""
  authorize = 0
  digit = 1
  screen.textCh("請輸入密碼",20,56,2,(255, 255, 255))
  screen.refresh()



def test():
  global lock_password,curr_password,curr_digit,x,y,authorize,digit

  if curr_password == lock_password:
    screen.fill((0, 255, 0))
    screen.textCh("密碼正確",35,50,2,(255, 255, 255))
    screen.refresh()
    authorize = 1
    buzzer.melody(CORRECT)
    robot.geekServo2kg(1, 90)
    sleep(1)
    while not Button("P1").value() == 0:
      pass
    sleep(1)
  else:
    screen.fill((255, 0, 0))
    screen.textCh("密碼錯誤",35,50,2,(255, 255, 255))
    screen.refresh()
    buzzer.melody(ERROR)
  init()



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)


robot = robotbit.RobotBit()

neopix=NeoPixel("P7",3)

screen.sync = 0

init()

while True:
  activate()
  if not authorize == 1:
    break_in()
```

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

### Program Instructions

Press the button to begin entering password, select a digit by turning the potentiometer, press the button to confirm. Once 4 digits have been entered, the safe door opens if the password is correct(default: 2021).


---

# 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/safe.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.
