Skip to content

Commit

Permalink
Add a simple love module to display a beating heart when imported.
Browse files Browse the repository at this point in the history
Includes a function within the module to redisplay the animation at will.
  • Loading branch information
ntoll authored and dpgeorge committed Sep 27, 2015
1 parent b792669 commit fe28329
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/genhdr/qstrdefs.generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ QDEF(MP_QSTR_panic, (const byte*)"\xd0\x05" "panic")
QDEF(MP_QSTR_this, (const byte*)"\xa3\x04" "this")
QDEF(MP_QSTR_authors, (const byte*)"\x63\x07" "authors")
QDEF(MP_QSTR_antigravity, (const byte*)"\xf1\x0b" "antigravity")
QDEF(MP_QSTR_love, (const byte*)"\x55\x04" "love")
QDEF(MP_QSTR_badaboom, (const byte*)"\x2c\x08" "badaboom")
QDEF(MP_QSTR_MicroBitPin, (const byte*)"\x77\x0b" "MicroBitPin")
QDEF(MP_QSTR_set_digital_value, (const byte*)"\x56\x11" "set_digital_value")
QDEF(MP_QSTR_get_digital_value, (const byte*)"\x42\x11" "get_digital_value")
Expand Down
2 changes: 2 additions & 0 deletions inc/microbit/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
extern const struct _mp_obj_module_t microbit_module;
extern const struct _mp_obj_module_t this_module;
extern const struct _mp_obj_module_t antigravity_module;
extern const struct _mp_obj_module_t love_module;

#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_microbit), (mp_obj_t)&microbit_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_this), (mp_obj_t)&this_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_antigravity), (mp_obj_t)&antigravity_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_love), (mp_obj_t)&love_module }, \
\
/* the following provide aliases for existing modules */ \
{ MP_OBJ_NEW_QSTR(MP_QSTR_collections), (mp_obj_t)&mp_module_collections }, \
Expand Down
3 changes: 3 additions & 0 deletions inc/microbit/qstrdefsport.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Q(authors)

Q(antigravity)

Q(love)
Q(badaboom)

Q(MicroBitPin)
Q(set_digital_value)
Q(get_digital_value)
Expand Down
75 changes: 75 additions & 0 deletions source/microbit/modlove.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Damien P. George
*
* 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"

void love(uint8_t interval = 500 /* ms */) {
// Display a beating heart then clear the screen.
const uint8_t heart[] = {
0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 1, 1, 1, 1,
0, 1, 1, 1, 0, 1, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
};
MicroBitImage i(10, 5, heart);
for(uint8_t iteration = 0; iteration < 5; iteration++) {
uBit.display.animate(i, interval, 5);
uBit.sleep(interval);
}
uBit.display.clear();
}

extern "C" {

#include "py/obj.h"

STATIC mp_obj_t love_badaboom(void) {
// make
love();
// ! war
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(love___init___obj, love_badaboom);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(love_badaboom_obj, love_badaboom);

STATIC const mp_map_elem_t love_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_love) },
{ MP_OBJ_NEW_QSTR(MP_QSTR___init__), (mp_obj_t)&love___init___obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_badaboom), (mp_obj_t)&love_badaboom_obj },
};

STATIC MP_DEFINE_CONST_DICT(love_module_globals, love_module_globals_table);

const mp_obj_module_t love_module = {
.base = { &mp_type_module },
.name = MP_QSTR_love,
.globals = (mp_obj_dict_t*)&love_module_globals,
};

}

0 comments on commit fe28329

Please sign in to comment.