kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Fix explorer micropython lib (#21)
* 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 <jon@pimoroni.com>pull/22/head v0.0.4
rodzic
356a8857c7
commit
1a1ed988ba
|
@ -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)
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Ładowanie…
Reference in New Issue