Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: Copyright (c) 2022 Jan Delgado
2# SPDX-License-Identifier: MIT
3"""
4JLed Hello world
5"""
6
7import board
8from jled import JLed
9
10led = JLed(board.LED).blink(500, 500).forever()
11
12while True:
13 led.update()
Pulse Effect (MicroPython)¶
This example targets a MicroPython device. The only difference to CircuitPython
is, that on MicroPython there is no board
package and therefore the pin are
addressed numerically.
1# SPDX-FileCopyrightText: Copyright (c) 2022 Jan Delgado
2# SPDX-License-Identifier: MIT
3"""
4JLead pulse effect example (micropython)
5"""
6
7from jled import JLed
8
9led1 = JLed(18).breathe(1000).min_brightness(20).delay_before(500).forever()
10led2 = JLed(23).breathe(1000).min_brightness(20).forever()
11
12while True:
13 led1.update()
14 led2.update()
Breathing LED¶
1# SPDX-FileCopyrightText: Copyright (c) 2022 Jan Delgado
2# SPDX-License-Identifier: MIT
3"""
4JLead breathe example
5"""
6
7import board
8from jled import JLed
9
10led = JLed(board.LED).breathe(1000).delay_after(500).forever()
11
12while True:
13 led.update()
Multiple LEDs¶
1# SPDX-FileCopyrightText: Copyright (c) 2022 Jan Delgado
2# SPDX-License-Identifier: MIT
3"""
4drive multiple LEDs using different effects with a JLedSequence
5"""
6
7import board
8from jled import JLed, JLedSequence
9
10led0 = JLed(board.LED).breathe(750).delay_after(250).forever()
11led1 = JLed(board.GP2).blink(500, 250).delay_after(250).forever()
12led2 = JLed(board.GP3).fade_off(1000).delay_after(500).forever()
13led3 = JLed(board.GP4).fade_on(1500).forever()
14
15seq = JLedSequence.parallel([led0, led1, led2, led3])
16
17while True:
18 seq.update()
User defined Effect¶
1# SPDX-FileCopyrightText: Copyright (c) 2022 Jan Delgado
2# SPDX-License-Identifier: MIT
3"""
4JLed User defined effect example
5"""
6
7import board
8from jled import JLed
9
10
11class UserEffect:
12 def __init__(self, period):
13 self._period = period
14
15 def eval(self, t):
16 """this function returns changes between 0 and 255 and
17 vice versa every period/2 ms"""
18 return 255 * ((t // (self._period >> 1)) & 1)
19
20 def period(self):
21 return self._period
22
23
24led = JLed(board.LED).user_func(UserEffect(1000)).forever()
25
26while True:
27 led.update()