Created
August 26, 2022 21:34
-
-
Save JoeKarlsson/ea9bdc3d5672e2f158f574f8199856e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from viam.robot.client import RobotClient | |
from viam.rpc.dial import Credentials, DialOptions | |
from viam.components.board import Board | |
async def connect(): | |
ADDRESS_SECRET = "[ADD YOUR ROBOT ADDRESS HERE. YOU CAN FIND THIS ON THE CONNECT TAB]" | |
PAYLOAD_SECRET = "[PLEASE ADD YOUR SECRET HERE. YOU CAN FIND THIS ON THE CONNECT TAB]" | |
creds = Credentials( | |
type='robot-location-secret', | |
payload=PAYLOAD_SECRET) | |
opts = RobotClient.Options( | |
refresh_interval=0, | |
dial_options=DialOptions(credentials=creds) | |
) | |
return await RobotClient.at_address(ADDRESS_SECRET, opts) | |
async def main(): | |
robot = await connect() | |
print('Resources:') | |
print(robot.resource_names) | |
local = Board.from_robot(robot, 'local') | |
led = await local.gpio_pin_by_name('8') | |
while (True): | |
# When True, sets the LED pin to high or on. | |
await led.set(True) | |
print('LED is on') | |
await asyncio.sleep(1) | |
# When False, sets the pin to low or off. | |
await led.set(False) | |
print('LED is off') | |
await asyncio.sleep(1) | |
await robot.close() | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment