ATC Remote
About ATC Remote Support
The ATC Remote support of Atom remote in MagiScript allows developers to connect your ATC to Atom, and control the ATC using commands.
Connecting To Your ATC
To connect Atom to a ATC, you need to use the atc.connect
method.
If Atom is not yet connected to an ATC device, it will start searching for it and then connect. If an ATC device is already connected, but the specified name is different, Atom will disconnect from the ATC device, and start searching for the specified name.
You can use theΒ *
character to connect to any available ATC 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.
atc.connect();
You can configure a default ATC device ID in the Atom Editor Settings. By default, it is *, which means it will connect to the first ATC device it finds.
Connecting by Specifying a Device Name
You can pass an ATC device ID as the first parameter, and Atom will connect to it.Β For example, to connect to an ATC with the ID “ATC-166666”, you would use the following command:
atc.connect('ATC-166666');
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
atc.connect('ATC-166666', connected);
function connected(event) {
console.log('ATC connected.');
}
atc.connect('ATC-166666', connected);
function connected(event) {
console.log('ATC connected.');
}
Using the atc.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() {
atc.connect();
// ...
}
Disconnecting your ATC
To disconnect your ATC, simply call the disconnect method. It will disconnect the active ATC device.
atc.disconnect();
You can also specify by it’s name which device you would like to disconnect:
atc.disconnect('ATC-036666');
Querying the Connected ATC
You can query the Bluetooth name (ID) of the ATC device(s) Atom connected to. The id method gives you the active device’s ID, while the ids method returns an array with the ATC devices Atom connected to.
atc.id(); // the active ATC device
atc.ids(); // all the ATC devices Atom connected to
You can query the connected ATC devices as a list of device objects as well using the list method.
const devs = atc.list();
for (let i = 0; i < devs.length; i++) {
console.log(devs[i].id, devs[i].battery);
}
If more than one ATC device is connected, you can set one of them to active with the select method. Messages will be sent to this unit.
atc.select('ATC-036666');
Battery Percentage
The battery level of ATC 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 = atc.battery();
console.log(atc battery level: ${percentage}%);
Blink with the ATC
atc.blink('..-'); // short-short-long
atc.blink('-.-.'); // long-short-long-short
atc.blink('-'); // Single long blink
Conclusion
The ATC support of Atom remote in MagiScript provides a convenient way for developers to connect their ATC to Atom and control its functions. By following the steps outlined in this documentation, you can easily connect to your ATC and set its time using MagiScript.
General
π First Steps
MagiScript Editor
π Basics
π Keyboard Shortcuts
π Running Your First Program
π App Store
π Debugging Techniques
Examples
π Atom Time
ποΈ Time Practice
π 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
π Quantum
π Teleport
π Spotted Dice
π SB Watch
π IARVEL Watch
π Fossil Watch
π Cosmos Printer
π PeriPage Printer
π ATC Remote
π Labko Scrabble
π Bluetooth Keyboard
π Bluetooth Mouse
π Timers
π Database
π Events
π System (exit, sleep, rand)
π Objects (card, time)
Language
π Summary
π Comments
π Operators
π Control Flow
π Functions
π Numbers
π Strings
π Arrays
π Objects
π Uint8Array