-
Notifications
You must be signed in to change notification settings - Fork 287
Create a "this" module and update help #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,34 +33,38 @@ | |
| STATIC const char *help_text = | ||
| "Welcome to MicroPython on the micro:bit!\n" | ||
| "\n" | ||
| "Be brave! Break things! Learn and have fun! :-)\n" | ||
| "\n" | ||
| "Type 'import microbit', press return and try these commands:\n" | ||
| " microbit.display.scroll('Hello')\n" | ||
| " microbit.system_time()\n" | ||
| " microbit.sleep(1000)\n" | ||
| " microbit.button_a.is_pressed()\n" | ||
| "What do these commands do? Can you improve them? HINT: use the up and down\n" | ||
| "arrow keys to get your command history (saves you typing).\n" | ||
| "arrow keys to get your command history. Press the TAB key to auto-complete\n" | ||
| "unfinished words (so 'mi' becomes 'microbit' after you press TAB). These\n" | ||
| "tricks save a lot of typing and look cool!\n" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean by "look cool"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a flippant remark... I put it in there as I remembered what a teacher told me at a past PyCon UK - kids like the look of the command line, it makes them look like, I dunno, they know what they're doing and it's how Hollywood portrays 1337 H4x0R5 (sigh). This is also related to engaging kids a la the "how did you do that?", "oh you don't know? Just use TAB like this..." situation where kids start to teach each other skills. Again, see my comments about fostering a sense of playful exploration and experimentation. Most kids would rather put their hand up and wait for the teacher to tell them to do something than actually poke around - we're facing an up-hill battle. Perhaps I'm too old a fuddy-duddy and there is a definite risk that I'm sounding far too "dad-ish" (i.e. uncool and trying too hard in terms of my language). Thoughts..? I'm not precious about any of the changes and prefer it when people push back so I have to either re-consider or change things to make it more obvious. |
||
| "\n" | ||
| "Explore:\n" | ||
| "Type 'help(something)' to find out about it. Type 'dir(something)' to see what\n" | ||
| "it can do.\n" | ||
| "it can do. For goodness sake, don't type 'import this'.\n" | ||
| "\n" | ||
| "Stuff to explore:\n" | ||
| " microbit.accelerometer -- detect the device's position (orientation)\n" | ||
| " microbit.button_a.is_pressed() -- is button A pressed? (True or False)\n" | ||
| " microbit.button_b.is_pressed() -- is button B pressed? (True or False)\n" | ||
| " microbit.compass -- detect the device's heading\n" | ||
| " microbit.display -- display things (pixels, characters, words)\n" | ||
| " microbit.panic() -- go into panic mode (requires a restart)\n" | ||
| " microbit.random(n) -- get a random number between 0 and n\n" | ||
| " microbit.io -- control the gold input/output (IO) pins\n" | ||
| " microbit.panic() -- enter panic mode (requires a restart)\n" | ||
| " microbit.random(n) -- get a random number between 0 and n-1\n" | ||
| " microbit.sleep(n) -- wait for n milliseconds (1 second = 1000)\n" | ||
| " microbit.system_time() -- get the number of milliseconds since reset\n" | ||
| "\n" | ||
| "Control commands:\n" | ||
| " CTRL-C -- stop a running program\n" | ||
| " CTRL-D -- on a blank line, do a soft reset of the micro:bit\n" | ||
| "\n" | ||
| "For more information about Python, visit: http://python.org/\n" | ||
| "To find out about MicroPython, visit: http://micropython.org/\n" | ||
| ; | ||
|
|
||
| typedef struct _mp_doc_t { | ||
|
|
@@ -73,11 +77,13 @@ STATIC const mp_doc_t help_table_types[] = { | |
| }; | ||
|
|
||
| STATIC const mp_doc_t help_table_instances[] = { | ||
| {µbit_module, "microbit module\n"}, | ||
| {µbit_sleep_obj, "sleep(ms) -- sleep for the given number of milliseconds\n"}, | ||
| {µbit_random_obj, "random(max) -- return a random integer between 0 and max-1\n"}, | ||
| {µbit_system_time_obj, "system_time() -- return an integer represeting the milliseconds since reset\n"}, | ||
| {µbit_panic_obj, "panic([code]) -- enter panic mode!\n"}, | ||
| {µbit_module, "A toolbox of code to control the micro:bit hardware\n"}, | ||
| {µbit_panic_obj, "panic() -- enter panic mode (requires a restart)\n"}, | ||
| {µbit_random_obj, "random(n) -- return a random number between 0 and n-1\n"}, | ||
| {µbit_sleep_obj, "sleep(n) -- wait for n milliseconds (1 second = 1000)\n"}, | ||
| {µbit_system_time_obj, "system_time() -- get the number of milliseconds since reset\n"}, | ||
| {µbit_accelerometer_obj, "A toolbox of code to detect the device's position (orientation)\n"}, | ||
| {µbit_accelerometer_get_x_obj, "Foo!\n"}, | ||
| }; | ||
|
|
||
| STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * This file is part of the Micro Python project, http://micropython.org/ | ||
| * | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2015 Damien P. George | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add copyright for your name as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hah... you can blame that on cut'n'paste. ;-) |
||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include "MicroBit.h" | ||
|
|
||
| extern "C" { | ||
|
|
||
| #include "py/obj.h" | ||
|
|
||
| STATIC mp_obj_t this__init__(void) { | ||
| STATIC const char *this_text = | ||
| "The Zen of MicroPython, by Nicholas H.Tollervey\n" | ||
| "\n" | ||
| "Code,\n" | ||
| "Hack it,\n" | ||
| "Less is more,\n" | ||
| "Keep it simple,\n" | ||
| "Small is beautiful,\n" | ||
| "\n" | ||
| "Be brave! Break things! Learn and have fun!\n" | ||
| "Express yourself with MicroPython.\n" | ||
| "\n" | ||
| "Happy hacking! :-)\n"; | ||
| mp_printf(&mp_plat_print, "%s", this_text); | ||
| return mp_const_none; | ||
| } | ||
| MP_DEFINE_CONST_FUN_OBJ_0(this___init___obj, this__init__); | ||
|
|
||
| STATIC mp_obj_t this_authors(void) { | ||
| /* | ||
| If you contribute code to this project, add your name here. | ||
| */ | ||
| STATIC const char *authors_text = | ||
| "MicroPython on the micro:bit is brought to you by:\n" | ||
| "Damien P.George and Nicholas H.Tollervey\n"; | ||
| mp_printf(&mp_plat_print, "%s", authors_text); | ||
| return mp_const_none; | ||
| } | ||
| STATIC MP_DEFINE_CONST_FUN_OBJ_0(this_authors_obj, this_authors); | ||
|
|
||
| STATIC const mp_map_elem_t this_module_globals_table[] = { | ||
| { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_this) }, | ||
| { MP_OBJ_NEW_QSTR(MP_QSTR___init__), (mp_obj_t)&this___init___obj }, | ||
| { MP_OBJ_NEW_QSTR(MP_QSTR_authors), (mp_obj_t)&this_authors_obj }, | ||
| }; | ||
|
|
||
| STATIC MP_DEFINE_CONST_DICT(this_module_globals, this_module_globals_table); | ||
|
|
||
| const mp_obj_module_t this_module = { | ||
| .base = { &mp_type_module }, | ||
| .name = MP_QSTR_this, | ||
| .globals = (mp_obj_dict_t*)&this_module_globals, | ||
| }; | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to give an example of pressing tab (via "so mi becomes microbit..."). Kids will work it out if they read that TAB does something special. And, actually, pressing TAB after mi will only work if you already imported microbit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd be surprised.
Auto-complete seems totally obvious to you and me, yet to an 11yo kid who has grown up in some of the places I used to teach (east end of London, wrong end of Slough, rough parts of Reading or anywhere in Bracknell etc...) this will be a totally alien concept. In fact, their literacy (let alone their typing) skills won't be fluent so any way we can "prod" them in the right direction so they engage because their life is made easier is a good thing (tm).
That they have to type will put off a significant minority of kids. My experience is that more help is better. Kids who don't need that guidance will just ignore it, or skim it, or use it to confirm their existing understanding.