โŒšSB Watch 2
๐Ÿšš Free fedex shipping from 97 $
๐ŸŒŽ WORLDWIDE SHIPPING for 25 $
Search
Close this search box.

Atom Pi (Pi Revelations) ยท MagiScript

David Penn's Pi Revelations

Pi Revelations is a stunning magic trick that will leave your spectators in awe. With the help of this trick, you can reveal your spectator’s PIN Number, Passcode, Date Of Birth, or Random Time in a unique and fascinating way – within the first fifty thousand decimals of Pi. The trick is sold with a book and a link to an indexing website, allowing you to create unbelievable revelations without the need for memory work.

BUY THE BOOK HERE: Pi Revelations by David Penn (worldmagicshop.com)

You will be able to enter the 4 digits on Atom, and it will reveal on PeekSmith where the digits are in the book (page, line number, and column). Atom stores the necessary logic to calculate this information, so we will have to query it.

See below the code for a Pi Revelations mini-app. It demonstrates how database queries will work, and also how you can implement entering numbers and doing calculations.

Please note, that the built-in Atom Time mini-app also supports displaying this information.

Thanks to Badasha Khan for helping me to add this feature.

How is it Working?

The main function runs when Atom loads your script (upload, or power on if you persisted the code). It connects to your PeekSmith.

The onEvent function is called when an event occurs. It displays “Atom Pi” on the PeekSmith when connected. For now, we are interested in button-press events from Atom. When an event like this happens, it transforms the value parameter to an integer number (it contains the button ID of Atom), and sends it to the onButtonPress function.

The onButtonPress function is processing the button ID. If it is a number button, it concatenates it to the number we are building. If it’s the button represents backspace, then it removes the last character if the num string is not empty. If it’s the bottom left button, then it just clears the number.

If the number has 4 digits, then it calculates the page information based on the number, and displays everything on the PeekSmith screen. Function showย responsible to display this information.

				
					
let num = '', lastNum = '';

function main() {
  ps.connect();
}

// Atom keyboard layout
const layout = [
  '1', '2', '3',
  '4', '5', '6',
  '7', '8', '9',
  'c', '0', '<'
];

function onButtonPress(buttonId) {
  const key = layout[buttonId];
  switch (key) {
    case 'c':
      num = '';
      lastNum = '';
      break;
    case '<':
      if (num === '' && lastNum !== '') num = lastNum;
      num = strSub(num, 0, -1);
      break;
    default:
      if (strLen(num) < 4) num += key;
      lastNum = '';
      break;
  }
  show();
}

function show() {
  let rest = '';
  for (let i = strLen(num); i < 4; i++) {
    rest += '_';
  }
  let text = `${num}${rest}\n`;
  if (strLen(num) === 4) {
    // query the information and display it
    const piInfo = db.query('pi', parseInt(num));
    text += `${piInfo.page} ${piInfo.line} ${piInfo.across}`;
    lastNum = num;
    num = '';
  }
  ps.print(text);
}

function onEvent(e) {
  if (e.source === 'ps:ble' && e.type === 'connected') {
    ps.print('Atom\nPi');
    setTimeout(show, 2000);
    return;
  }
  if (e.source === 'atom:button') {
    const buttonId = parseInt(e.value);
    if (e.type === 'click' || e.type === 'repeatpress') {
      return onButtonPress(buttonId);
    }
    if (strSub(e.type, 0, 5) === 'click' && strLen(e.type) === 6) {
      const clickCount = parseInt(strCharAt(e.type, 5));
      for (let i = 0; i < clickCount; i++) {
        onButtonPress(buttonId);
      }
      return;
    }
  }
}

				
			

Challanges

Modify the code to clear the screen (ps.print('')) if the number has no digits. It will save a lot of (PeekSmith 3) battery.

Don’t allow the code to add new digits if the number already has four digits.

General

๐Ÿ“ƒย First Steps

MagiScript Editor

๐Ÿ“ƒย Basics

๐Ÿ“ƒย Running Your First Program

๐Ÿ“ƒย App Store

๐Ÿ“ƒย Atom Settings (Editor)

๐Ÿ“ƒย Debugging Techniques

Examples

๐Ÿ“ƒย Atom Time

๐ŸŽž๏ธ Time Practice

๐Ÿ“ƒย Atom Pi (Pi Revelations)

๐Ÿ“ƒย Atom Drum

๐ŸŽž๏ธ Atom Stack

๐Ÿ“ƒย Atom Square

๐Ÿ“ƒย Atom Level

๐Ÿ“ƒย Atom THMPR

๐Ÿ“ƒย Poker Hands

๐Ÿ“ƒย Keyboard Numeric

๐Ÿ“ƒย Keyboard NOKIA

๐Ÿ“ƒย Keyboard Cursor

๐Ÿ“ƒย Keyboard Media

๐Ÿ“ƒย Keyboard Custom

Input/Output

๐Ÿ“ƒย Buttons

๐Ÿ“ƒย Vibration Motor

๐Ÿ“ƒย RGB LED

๐Ÿ“ƒย Devices

๐Ÿ“ƒย PeekSmith

๐Ÿ“ƒย SB Watch

๐Ÿ“ƒย Bluetooth Keyboard

๐Ÿ“ƒย Bluetooth Mouse

๐Ÿ“ƒย Timers

๐Ÿ“ƒย Database

๐Ÿ“ƒย Events

๐Ÿ“ƒย System (exit, sleep, rand)

๐Ÿ“ƒย Objects (card, time)

Language

๐Ÿ“ƒย Summary

๐Ÿ“ƒย Comments

๐Ÿ“ƒย Variable Declarations

๐Ÿ“ƒย Operators

๐Ÿ“ƒย Control Flow

๐Ÿ“ƒย Functions

๐Ÿ“ƒย Numbers

๐Ÿ“ƒย Strings

๐Ÿ“ƒย Arrays

๐Ÿ“ƒย Objects

๐Ÿ“ƒย Uint8Array