Skip to content

Commit

Permalink
add samples
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Mar 31, 2023
1 parent 436a48a commit 885e08e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
24 changes: 24 additions & 0 deletions website/docs/getting-started/samples/rp2040/blinky.mdx
@@ -0,0 +1,24 @@
# Blinky

The classic LED blinking program on a Raspberry Pi Pico. The LED is connected to the Pico's pin GP1 (2 on the silk)

```ts
import { pins } from "@dsboard/pico"
import { startLightBulb } from "@devicescript/servers"

// start a lightbulb server on pin GP1
// and store client in `led` variable
const led = startLightBulb({
pin: pins.P1,
})

// start interval timer every 1000ms
setInterval(async () => {
// read current brightness
const brightness = await led.brigthness.read()
// toggle on/off
const newbrightness = brightness > 0 ? 0 : 1
// apply new brightness
await led.brigthness.write(newbrightness)
}, 1000)
```
40 changes: 40 additions & 0 deletions website/docs/getting-started/samples/rp2040/copy-paste-button.mdx
@@ -0,0 +1,40 @@
---
hide_table_of_contents: true
---

# Copy Paste Button

```ts
import { pins } from "@dsboard/pico"
import {
startButton,
startHidKeyboard,
startLightBulb,
} from "@devicescript/servers"
import {
HidKeyboardAction,
HidKeyboardModifiers,
HidKeyboardSelector,
} from "@devicescript/core"

const button = startButton({
pin: pins.P14,
})
const led = startLightBulb({
pin: pins.P1,
})
const keyboard = startHidKeyboard({})
let copy = true
button.down.subscribe(async () => {
const selector = copy ? HidKeyboardSelector.C : HidKeyboardSelector.V
const brightness = copy ? 1 : 0
console.log(copy ? 'ctrl+c' : 'ctrl+v')
await keyboard.key(
selector,
HidKeyboardModifiers.LeftControl,
HidKeyboardAction.Press
)
await led.brightness.write(brightness)
copy = !copy
})
```

0 comments on commit 885e08e

Please sign in to comment.