Skip to content

Commit

Permalink
Fix explorer micropython lib (#21)
Browse files Browse the repository at this point in the history
* fixed explorer library, added to cmake, and added quick demo

* display status of motors during demo

* increase motor power in demo

Co-authored-by: Jonathan Williamson <[email protected]>
  • Loading branch information
Gadgetoid and Jonathan Williamson authored Jan 24, 2021
1 parent 356a885 commit 1a1ed98
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
62 changes: 62 additions & 0 deletions micropython/examples/pico_explorer/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import time, random
import picoexplorer as explorer

width = explorer.get_width()
height = explorer.get_height()

display_buffer = bytearray(width * height * 2) # 2-bytes per pixel (RGB565)
explorer.init(display_buffer)

explorer.set_backlight(1.0)
explorer.set_audio_pin(0)

i = 1

while True:
explorer.set_pen(120, 40, 60)
explorer.clear()

adc0 = int(explorer.get_adc(0) * 120)
adc1 = int(explorer.get_adc(1) * 120)
adc2 = int(explorer.get_adc(2) * 120)

explorer.set_pen(255, 255, 255)

explorer.text("ADC0:", 20, 20, 100)
explorer.text("ADC1:", 20, 40, 100)
explorer.text("ADC2:", 20, 60, 100)

explorer.set_pen(adc0 * 2, 0, 0)
explorer.circle(90 + adc0, 26, 10)

explorer.set_pen(0, adc1 * 2, 0)
explorer.circle(90 + adc1, 46, 10)

explorer.set_pen(0, 0, adc2 * 2)
explorer.circle(90 + adc2, 66, 10)

explorer.set_pen(255, 255, 255)
explorer.text("Plug a jumper wire from GP0 to AUDIO to hear noise!", 20, 110, 200)

explorer.set_tone(i)

if i > 600:
explorer.text("Motor 1: Forwards", 20, 180, 200)
explorer.set_motor(0, 0, 1)
else:
explorer.text("Motor 1: Backwards", 20, 180, 200)
explorer.set_motor(0, 1, 1)

if i > 600:
explorer.text("Motor 2: Forwards", 20, 200, 200)
explorer.set_motor(1, 0, 1)
else:
explorer.text("Motor 2: Backwards", 20, 200, 200)
explorer.set_motor(1, 1, 1)

i = i + 20
if i > 1000:
i = 1

explorer.update()
time.sleep(0.01)
20 changes: 10 additions & 10 deletions micropython/modules/pico_explorer/pico_explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern mp_obj_t picoexplorer_get_adc(mp_obj_t channel_obj) {
mp_raise_ValueError("adc channel not valid. Expected 0 to 2");
else
reading = explorer->get_adc(channel);

return mp_obj_new_float(reading);
}

Expand Down Expand Up @@ -180,7 +180,7 @@ mp_obj_t picoexplorer_create_pen(mp_obj_t r_obj, mp_obj_t g_obj, mp_obj_t b_obj)
mp_raise_ValueError("b out of range. Expected 0 to 255");
else
pen = explorer->create_pen(r, g, b);

return mp_obj_new_int(pen);
}

Expand All @@ -192,7 +192,7 @@ mp_obj_t picoexplorer_set_clip(mp_uint_t n_args, const mp_obj_t *args) {
int w = mp_obj_get_int(args[2]);
int h = mp_obj_get_int(args[3]);

rect r(x, y, w, h);
Rect r(x, y, w, h);
explorer->set_clip(r);

return mp_const_none;
Expand All @@ -212,9 +212,9 @@ mp_obj_t picoexplorer_pixel(mp_obj_t x_obj, mp_obj_t y_obj) {
int x = mp_obj_get_int(x_obj);
int y = mp_obj_get_int(y_obj);

point p(x, y);
Point p(x, y);
explorer->pixel(p);

return mp_const_none;
}

Expand All @@ -223,7 +223,7 @@ mp_obj_t picoexplorer_pixel_span(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t l_obj)
int y = mp_obj_get_int(y_obj);
int l = mp_obj_get_int(l_obj);

point p(x, y);
Point p(x, y);
explorer->pixel_span(p, l);

return mp_const_none;
Expand All @@ -237,7 +237,7 @@ mp_obj_t picoexplorer_rectangle(mp_uint_t n_args, const mp_obj_t *args) {
int w = mp_obj_get_int(args[2]);
int h = mp_obj_get_int(args[3]);

rect r(x, y, w, h);
Rect r(x, y, w, h);
explorer->rectangle(r);

return mp_const_none;
Expand All @@ -248,7 +248,7 @@ mp_obj_t picoexplorer_circle(mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t r_obj) {
int y = mp_obj_get_int(y_obj);
int r = mp_obj_get_int(r_obj);

point p(x, y);
Point p(x, y);
explorer->circle(p, r);

return mp_const_none;
Expand All @@ -259,7 +259,7 @@ mp_obj_t picoexplorer_character(mp_uint_t n_args, const mp_obj_t *args) {
int x = mp_obj_get_int(args[1]);
int y = mp_obj_get_int(args[2]);

point p(x, y);
Point p(x, y);
if(n_args == 4) {
int scale = mp_obj_get_int(args[3]);
explorer->character((char)c, p, scale);
Expand All @@ -280,7 +280,7 @@ mp_obj_t picoexplorer_text(mp_uint_t n_args, const mp_obj_t *args) {
int y = mp_obj_get_int(args[2]);
int wrap = mp_obj_get_int(args[3]);

point p(x, y);
Point p(x, y);
if(n_args == 5) {
int scale = mp_obj_get_int(args[4]);
explorer->text(t, p, wrap, scale);
Expand Down
3 changes: 2 additions & 1 deletion micropython/modules/usermod.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(${CMAKE_CURRENT_LIST_DIR}/pico_scroll/usermod.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/pico_rgb_keypad/usermod.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/pico_unicorn/usermod.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/pico_display/usermod.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/pico_display/usermod.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/pico_explorer/usermod.cmake)

0 comments on commit 1a1ed98

Please sign in to comment.