From ff81658066c55eb336b6f977b143e594b1e16e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Correia=20Marques?= Date: Sat, 16 Jul 2022 18:58:26 +0100 Subject: [PATCH 1/3] add blink example for pico w --- blink-pico-w/README.md | 23 +++++++++++++++++++++++ blink-pico-w/index.js | 7 +++++++ blink-pico-w/package.json | 4 ++++ 3 files changed, 34 insertions(+) create mode 100644 blink-pico-w/README.md create mode 100644 blink-pico-w/index.js create mode 100644 blink-pico-w/package.json diff --git a/blink-pico-w/README.md b/blink-pico-w/README.md new file mode 100644 index 0000000..c38abfe --- /dev/null +++ b/blink-pico-w/README.md @@ -0,0 +1,23 @@ +# Overview + +A blink example for Raspberry Pi Pico W. Contrary to the regular Pico, the LED on this board is connected to the WiFi chip (CYW43). + +# Code + +Turn on and off the on-board LED for every seconds. + +```js +var led = 0 +const cyw43_arch = require('cyw43_arch'); + +cyw43_arch.gpioPut(led, 1); +setInterval(() => { + cyw43_arch.gpioPut(led, 0); +}, 1000); +``` + +# See also + +- [pinMode()](https://kalumajs.org/docs/api/digital-io#pinmode) +- [digitalToggle()](https://kalumajs.org/docs/api/digital-io#digitaltoggle) +- [setInterval()](https://kalumajs.org/docs/api/timers#setinterval) diff --git a/blink-pico-w/index.js b/blink-pico-w/index.js new file mode 100644 index 0000000..45af3d1 --- /dev/null +++ b/blink-pico-w/index.js @@ -0,0 +1,7 @@ +var led = 0 +const cyw43_arch = require('cyw43_arch'); + +cyw43_arch.gpioPut(led, 1); +setInterval(() => { + cyw43_arch.gpioPut(led, 0); +}, 1000); \ No newline at end of file diff --git a/blink-pico-w/package.json b/blink-pico-w/package.json new file mode 100644 index 0000000..6d47aed --- /dev/null +++ b/blink-pico-w/package.json @@ -0,0 +1,4 @@ +{ + "name": "blink-pico-w", + "description": "Blink the on-board LED on a Raspberry Pico W" +} From 19691eeb3073d922ceac73a82a93d4c2463b6f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Correia=20Marques?= Date: Sun, 17 Jul 2022 12:49:11 +0100 Subject: [PATCH 2/3] make it actually blink --- blink-pico-w/index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/blink-pico-w/index.js b/blink-pico-w/index.js index 45af3d1..dee7b8f 100644 --- a/blink-pico-w/index.js +++ b/blink-pico-w/index.js @@ -1,7 +1,8 @@ -var led = 0 const cyw43_arch = require('cyw43_arch'); +const led = 0 +let state = 1; -cyw43_arch.gpioPut(led, 1); setInterval(() => { - cyw43_arch.gpioPut(led, 0); -}, 1000); \ No newline at end of file + cyw43_arch.gpioPut(led, state); + state = (state + 1 ) % 2; // Toggle between 1 and 0 +}, 1000); From 2c58678568081d88f26e4757f2762e4dfcb78460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Correia=20Marques?= Date: Sun, 17 Jul 2022 12:49:58 +0100 Subject: [PATCH 3/3] Update README.md --- blink-pico-w/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/blink-pico-w/README.md b/blink-pico-w/README.md index c38abfe..c9087d2 100644 --- a/blink-pico-w/README.md +++ b/blink-pico-w/README.md @@ -7,12 +7,13 @@ A blink example for Raspberry Pi Pico W. Contrary to the regular Pico, the LED o Turn on and off the on-board LED for every seconds. ```js -var led = 0 const cyw43_arch = require('cyw43_arch'); +const led = 0 +let state = 1; -cyw43_arch.gpioPut(led, 1); setInterval(() => { - cyw43_arch.gpioPut(led, 0); + cyw43_arch.gpioPut(led, state); + state = (state + 1 ) % 2; // Toggle between 1 and 0 }, 1000); ```