Skip to content

Commit eaf0b59

Browse files
committed
Always use the core1 backlight.
Add set_led_rgb and set_led_hsv directly to Presto for user backlight control. Update docs and examples accordingly.
1 parent 4d41681 commit eaf0b59

File tree

9 files changed

+165
-125
lines changed

9 files changed

+165
-125
lines changed

docs/presto.md

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
# Presto
1+
# Presto <!-- omit in toc -->
22

33
Most of your interaction with Presto will be through the `presto` module.
44

55
It will help you set up PicoGraphics, touch, WiFi, ambient lighting and more.
66

7+
- [Getting Started](#getting-started)
8+
- [Features](#features)
9+
- [Updating The Display](#updating-the-display)
10+
- [Touch](#touch)
11+
- [Back/Ambient Lights](#backambient-lights)
12+
- [Auto LEDs](#auto-leds)
13+
- [Manual LEDs](#manual-leds)
14+
- [Wireless](#wireless)
15+
716
## Getting Started
817

918
Create a new Presto instance:
@@ -58,43 +67,22 @@ To access touch information you can use:
5867

5968
### Back/Ambient Lights
6069

70+
#### Auto LEDs
71+
6172
If you've set `ambient_light=True` then Presto will automatically update the LEDs
6273
to match the screen content.
6374

6475
Note - you can disable this with `presto.auto_ambient_leds(False)`.
6576

66-
Otherwise you can use either MicroPython's `neopixel` library or our `Plasma` to
67-
drive the LEDs.
77+
#### Manual LEDs
6878

69-
#### Using the NeoPixel Library
70-
71-
```python
72-
import neopixel
73-
74-
NUM_LEDS = 7
75-
LED_PIN = 33
76-
77-
lights = neopixel.NeoPixel(machine.Pin(LED_PIN), NUM_LEDS)
78-
79-
lights[0] = (255, 255, 0)
80-
81-
lights.write()
82-
```
83-
84-
#### Using the Plasma Library
79+
With Presto's auto backlighting disabled you can control the LED colours
80+
manually, like so:
8581

8682

8783
```python
88-
import plasma
89-
90-
NUM_LEDS = 7
91-
LED_PIN = 33
92-
93-
lights = plasma.WS2812(NUM_LEDS, 0, 0, LED_PIN)
94-
lights.start()
95-
96-
lights.set_hsv(0, 0.5, 1.0, 1.0)
97-
lights.set_rgb(1, 255, 255, 0)
84+
presto.set_led_hsv(0, 0.5, 1.0, 1.0)
85+
presto.set_led_rgb(1, 255, 255, 0)
9886
```
9987

10088
### Wireless

examples/backlight_basic.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/cheerlights_bulb.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ def show_message(text):
145145
while True:
146146
show_message(e)
147147

148-
# WS2812 / NeoPixel™ LEDs used for the backlight
149-
bl = plasma.WS2812(7, 0, 0, 33)
150-
bl.start()
151-
152148
# Centre points
153149
CX = WIDTH // 2
154150
CY = HEIGHT // 2
@@ -257,7 +253,7 @@ def get_cheerlight():
257253
draw_bulb(colour)
258254

259255
for i in range(7):
260-
bl.set_rgb(i, *colour)
256+
presto.set_led_rgb(i, *colour)
261257

262258
time.sleep(0.02)
263259

@@ -266,7 +262,7 @@ def get_cheerlight():
266262
display.clear()
267263

268264
for i in range(7):
269-
bl.set_rgb(i, 0, 0, 0)
265+
presto.set_led_rgb(i, 0, 0, 0)
270266

271267
time.sleep(0.02)
272268

examples/image_gallery.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
# JPEG Dec
4646
j = jpegdec.JPEG(display)
4747

48-
# Plasma setup
49-
bl = plasma.WS2812(7, 0, 0, 33)
50-
bl.start()
51-
5248
# Where our images are located
5349
directory = 'gallery'
5450

@@ -231,23 +227,23 @@ def clear():
231227
# The LEDs on the right side of the presto light up to show it is working
232228
if touch.x > WIDTH // 2:
233229
for i in LEDS_RIGHT:
234-
bl.set_rgb(i, 255, 255, 255)
230+
presto.set_led_rgb(i, 255, 255, 255)
235231
show_image(show_next=True)
236232
presto.update()
237233
last_updated = time.time()
238234
for i in LEDS_RIGHT:
239-
bl.set_rgb(i, 0, 0, 0)
235+
presto.set_led_rgb(i, 0, 0, 0)
240236
time.sleep(0.01)
241237

242238
# Left half of the screen moves to the previous image
243239
elif touch.x < WIDTH // 2:
244240
for i in LEDS_LEFT:
245-
bl.set_rgb(i, 255, 255, 255)
241+
presto.set_led_rgb(i, 255, 255, 255)
246242
show_image(show_previous=True)
247243
presto.update()
248244
last_updated = time.time()
249245
for i in LEDS_LEFT:
250-
bl.set_rgb(i, 0, 0, 0)
246+
presto.set_led_rgb(i, 0, 0, 0)
251247
time.sleep(0.01)
252248

253249
# Wait here until the user stops touching the screen

examples/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
os.remove("/ramfs/launch.txt")
2121
__import__(result[:-3])
2222

23-
bl = plasma.WS2812(7, 0, 0, 33)
24-
bl.start()
25-
2623
# Setup for the Presto display
2724
presto = Presto(ambient_light=False)
2825

@@ -357,6 +354,6 @@ def launch(self):
357354
# Cycle the hue of the backlight LEDs to match the icon colours
358355
hue = 1.0 - (move_angle % (2 * math.pi)) / (2 * math.pi)
359356
for i in range(7):
360-
bl.set_hsv(i, hue, 1.0, 0.5)
357+
presto.set_led_hsv(i, hue, 1.0, 0.5)
361358

362359
presto.update()

modules/c/presto/presto.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ MP_DEFINE_CONST_FUN_OBJ_KW(Presto_partial_update_obj, 5, Presto_partial_update);
99
MP_DEFINE_CONST_FUN_OBJ_2(Presto_set_backlight_obj, Presto_set_backlight);
1010
MP_DEFINE_CONST_FUN_OBJ_2(Presto_auto_ambient_leds_obj, Presto_auto_ambient_leds);
1111

12+
MP_DEFINE_CONST_FUN_OBJ_KW(Presto_set_led_rgb_obj, 5, Presto_set_led_rgb);
13+
MP_DEFINE_CONST_FUN_OBJ_KW(Presto_set_led_hsv_obj, 3, Presto_set_led_hsv);
14+
1215
/***** Binding of Methods *****/
1316

1417
static const mp_rom_map_elem_t Presto_locals_dict_table[] = {
@@ -17,6 +20,8 @@ static const mp_rom_map_elem_t Presto_locals_dict_table[] = {
1720
{ MP_ROM_QSTR(MP_QSTR_partial_update), MP_ROM_PTR(&Presto_partial_update_obj) },
1821
{ MP_ROM_QSTR(MP_QSTR_set_backlight), MP_ROM_PTR(&Presto_set_backlight_obj) },
1922
{ MP_ROM_QSTR(MP_QSTR_auto_ambient_leds), MP_ROM_PTR(&Presto_auto_ambient_leds_obj) },
23+
{ MP_ROM_QSTR(MP_QSTR_set_led_rgb), MP_ROM_PTR(&Presto_set_led_rgb_obj) },
24+
{ MP_ROM_QSTR(MP_QSTR_set_led_hsv), MP_ROM_PTR(&Presto_set_led_hsv_obj) },
2025

2126
{ MP_ROM_QSTR(MP_QSTR_WIDTH), MP_ROM_INT(WIDTH/2) },
2227
{ MP_ROM_QSTR(MP_QSTR_HEIGHT), MP_ROM_INT(HEIGHT/2) },

0 commit comments

Comments
 (0)