⚛️ Atom 2 Smart Remote   🚚 FREE FEDEX SHIPPING from 397 USD   🌎 WORLDWIDE SHIPPING for 25 USD

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.

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 (modify the device name in line 2 to match yours), and prints AtomPi.

The onEvent function happens when an event occurs. 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.

Finally, 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 top 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 main() {

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

function onButtonPress(buttonId) {
    let key = layout[buttonId];
    // get which digit is assigned to the button
    if (key === 'c') {
        num = '';
    } else
    if (key === '<') {
        if (strLen(num) > 0) num = strSub(num, 0, strLen(num) - 1);
    } else {
        num += key;
    let text = `<${num}>\n`;
    if (strLen(num) === 4) {
        // query the information and display it
        let piInfo = db.query("pi", parseInt(num));
        text += `${piInfo.page} ${piInfo.line} ${piInfo.across}`;

function onEvent(e) {
    // only care about button presses
    if (e.source === 'atom:button' && e.type === 'press') {


  • 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.