Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
40
website/docs/getting-started/samples/rp2040/copy-paste-button.mdx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
``` |