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

PeekSmith

About

The PeekSmith support of Atom remote in MagiScript allows developers to connect your PeekSmith to Atom, and control the watch using commands.ย PeekSmith 3ย orย SuperPeekย are supported. You can:

  • display messages on its screen,
  • send vibration patterns,
  • turn its accelerometer reporting on/off,
  • receive button events.

Connecting to a PeekSmith

To interact with a PeekSmith device, you must first connect to it using the `ps. connect` method.

If Atom is not yet connected to a PeekSmith device, it will start searching for it and then connect. If a PeekSmith device is already connected, but the specified name is different, Atom will disconnect from the PeekSmith device, and start searching for the specified name.

You can use theย *ย character to connect to any available PeekSmith device.

The method is flexible regarding its parameters. Let’s review the possible options.

Connecting without a Device Name

This is the recommended way to connect, as this way you can share your code and no change will be necessary.

				
					ps.connect();
				
			

You can configure a default PeekSmith device ID in the Atom Editor Settings. By default, it isย *, which means it will connect to the first PeekSmith device it finds.

Connecting by Specifying a Device Name

You can pass a PeekSmith device ID as the first parameter, and Atom will connect to it.

				
					ps.connect('PeekSmith-036666');
				
			

This is the legacy way, we recommend using it only if you have a specific use case.

Connecting by Specifying a Device Name and a Callback

As a second parameter, you can specify a callback function. It will be called when Atom successfully connects to the PeekSmith device. It will be called immediately if Atom is already connected to a PeekSmith.

				
					ps.connect('PeekSmith-036666', connected);

function connected(event) {
  console.log('PeekSmith connected.');
}
				
			
When a PeekSmith is connected, then an event will be triggered. Both the onEvent function, and the callback will be called with the event details.

				
					ps.connect('PeekSmith-036666', connected);

function connected(event) {
  console.log('PeekSmith connected.');
}
				
			

Using the ps.connect Method

The best way to connect is by adding this call to the beginning of the main function, which runs when the code is loaded.

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

Disconnecting your PeekSmith

To disconnect your PeekSmith, simply call the disconnect method. It will disconnect the active PeekSmith device.

				
					ps.disconnect();
				
			

You can also specify by it’s name which device you would like to disconnect:

				
					ps.disconnect('PeekSmith-036666');
				
			

Querying the Connected PeekSmith(s)

You can query the Bluetooth name (ID) of the PeekSmith device(s) Atom connected to. The id method gives you the active device’s ID, while the ids method returns an array with the PeekSmith devices Atom connected to.

				
					atom.id(); // the active PeekSmith device
atom.ids(); // all the PeekSmith devices Atom connected to
				
			

You can query the connected PeekSmith devices as a list of device objects as well using the list method.

				
					const devs = ps.list();
for (let i = 0; i < devs.length; i++) {
  console.log(devs[i].id, devs[i].battery);
}
				
			

If more than one PeekSmith device is connected, you can set one of them to active with the select method. Messages will be sent to this unit.

				
					ps.select('PeekSmith-036666');
				
			

Displaying Text on PeekSmith Screen

Once you have connected to a PeekSmith device, you can display text on its screen using the ps.print method. The method takes a single argument, which is the text that you want to display on the screen. If PeekSmith is not yet connected, MagiScript will collect your messages and send them as soon as a device is connected.

For example, if you want to display the text “Hello World” on the PeekSmith screen, you can use the following code:

				
					ps.print('Hello World');
				
			

This will display the text “Hello World” on the PeekSmith screen.

Using PeekSmith’s “Smart Text”, you can display cards or colors on the screen like sending messages:

				
					ps.print('AH');        // displays an Ace of Heart
ps.print('7D KS');     // seven of diamonds, king of spades
ps.pring('star');      // displays a star ESP sign
ps.print('yellow');    // displays a yellow card
				
			

Vibrating PeekSmith

You can also vibrate the PeekSmith device using the ps.vibrate method. The method takes a single argument, which is the pattern that you want to vibrate.

For example, if you want to vibrate the PeekSmith device with a pattern of three short vibrations, you can use the following code:

				
					ps.vibrate('...');
				
			

This will vibrate the PeekSmith device three times in a short pattern. The latest PeekSmith firmware supports the same patterns as Atom (except the short tick).

Accelerometer Data (since firmware v1.1.31)

PeekSmith 3 has an accelerometer, and Atom can turn it on or off. When turned on, the accelerometer will start reporting raw x, y, and z data.

Accelerometer ON

There are more ways to turn on the accelerometer, but they have the same effect:

				
					ps.accel('on'); // please note that ON or On will not work
ps.accel(true);
				
			

Accelerometer OFF

Turning off the accelerometer is similar:

				
					ps.accel('off'); // please note that OFF or Off will not work
ps.accel(false);
				
			

Accelerometer Data

You will start receiving events with XYZ data when you turn on the accelerometer via the onEvent function. The value is going to be comma-separated numbers, the type ‘xyz’, and the source ‘ps::accel’.

Example

Here’s an example code of how you can use them:

				
					function main() {
  ps.connect('PeekSmith-031060');
  ps.accel('on');
}

function onEvent(value, type, source) {
  if (type === 'xyz' && source === 'ps:accel') {
    let xyz = strSplit(value, ',');
    let x = parseInt(xyz[0]);
    let y = parseInt(xyz[1]);
    let z = parseInt(xyz[2]);
    console.log(x, y, z);
  }
}
				
			

Battery Percentage

The battery level of PeekSmith can be queried with the battery method. It reports a number between 0 and 100. It is checked when Atom connects to the device, and is subsequently updated every other minute.

				
					const percentage = atom.battery();
console.log(Atom battery level: ${percentage}%);
				
			

Receiving Button Events

When a PeekSmith is connected, it will start sending button press and release events. PeekSmith has 3 buttons, #0 is the side button, #1 is the front left button, and #2 is the front right button. You can process them with the onEvent function.

Read our Buttons documentation page for more details.

Conclusion

MagiScript provides an easy way to connect to and control PeekSmith devices directly from Atom. By using the ps.connect, ps.print, and ps.vibrate methods, you can interact with the PeekSmith device and display text and patterns on its screen, as well as vibrate it.

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