<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.sha2017.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pim</id>
		<title>SHA2017 Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.sha2017.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pim"/>
		<link rel="alternate" type="text/html" href="https://wiki.sha2017.org/w/Special:Contributions/Pim"/>
		<updated>2026-04-22T21:43:59Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.3</generator>

	<entry>
		<id>https://wiki.sha2017.org/index.php?title=Projects:Badge/MicroPython&amp;diff=10470</id>
		<title>Projects:Badge/MicroPython</title>
		<link rel="alternate" type="text/html" href="https://wiki.sha2017.org/index.php?title=Projects:Badge/MicroPython&amp;diff=10470"/>
				<updated>2017-08-04T20:59:18Z</updated>
		
		<summary type="html">&lt;p&gt;Pim: /* import badge */  Added easier way to generate a bytestring for the LEDs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Badgemenu}}&lt;br /&gt;
== MicroPython ==&lt;br /&gt;
===WIP===&lt;br /&gt;
&lt;br /&gt;
Currently a fast moving target, documentation should be up-to-date though . .&lt;br /&gt;
&lt;br /&gt;
Connect to your badge with your favourite serial terminal (e.g. `picocom /dev/ttyUSB0 -b115200`) for a REPL, or start the [[Projects:Badge/Emulator|emulator]].&lt;br /&gt;
&lt;br /&gt;
You can use [[Projects:Badge/ampy|ampy]] or  [[Projects:Badge/mpfshell|mpfshell]] to connect to your badge too.&lt;br /&gt;
&lt;br /&gt;
To be able to start a REPL you need the clean_repl egg from the hatchery: https://badge.sha2017.org/projects/clean_repl . This will restart the badge, starts nothing and makes it possible to use the REPL.&lt;br /&gt;
&lt;br /&gt;
==help()==&lt;br /&gt;
&lt;br /&gt;
This should get you started hacking right away.&lt;br /&gt;
&lt;br /&gt;
==import esp==&lt;br /&gt;
&lt;br /&gt;
This module hosts some of the low-level ESP32 features.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import esp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtc_get_reset_reason(cpu)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Where CPU is 0 or 1, other values for CPU always return 0.&lt;br /&gt;
&lt;br /&gt;
Returns the [http://esp32.info/docs/esp_idf/html/db/dc1/group__rtc__apis.html#ga826b88529aef76135636c06d408513aa reset reason] of last reset event.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.start_sleeping(miliseconds)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Put the processors to sleep for the given amount of time . .&lt;br /&gt;
&lt;br /&gt;
Reading and writing of RTC memory '''currently doesn't keep contents over deep-sleep!'''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_write(offset, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Sets value at offset.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_read(offset)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns value stored at offset.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_write_string(string, offset = 2)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Sets string value at optional offset.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_read_string(offset = 2)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns string value stored at optional offset.&lt;br /&gt;
&lt;br /&gt;
NB: To set a program for boot run, put in the name at offset two and make sure the values of offset 0 and 1 are not each others inverse ;)&lt;br /&gt;
&lt;br /&gt;
==import badge==&lt;br /&gt;
&lt;br /&gt;
The first thing you would want to do is get the display working, this is currently done by the &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import badge&lt;br /&gt;
badge.init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise all badge peripherals, this is probably the way you want to start your app.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.eink_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Just init the screen.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.eink_busy()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a &amp;lt;code&amp;gt;boolean&amp;lt;/code&amp;gt; value to indicate eink is currently being flushed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.eink_busy_wait()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Waits for the eink to be flushed, handy to use before you deepsleep.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.power_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise power sensing and related pin states.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.battery_charge_status()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a boolean, true for charging, false for not charging.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.battery_volt_sense()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a value somewhat representing the battery voltage in milivolts ('''needs calibration)'''!&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.usb_volt_sense()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a value somewhat representing the USB voltage in milivolts ('''needs calibration)'''!&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise power to the LEDs and setup the SPI bus.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_enable()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise power to the LEDs (automagically done by &amp;lt;code&amp;gt;badge.leds.init()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_disable()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Disable power to the LEDs.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_send_data(grbw_values, length)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Stream a given length GRBW values to the LEDs over the SPI bus.&lt;br /&gt;
&lt;br /&gt;
Length should probably be 24 (4 bytes, 6 LEDs) . .&lt;br /&gt;
&lt;br /&gt;
A bytestring can be generated from a list by using something like: bytes([255, 0, 0, 100, 255, 0, 0, 100, 255, 0, 0, 100, 255, 0, 0, 100, 255, 0, 0, 100, 255, 0, 0, 100])&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.vibrator_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Setup the vibrator driver.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.vibrator_activate(pattern)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Send some interesting buzz patterns to the vibrator. .&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_get_str(namespace, key, default)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Return a string from Non Volatile Storage under namespace, key fall back to default if None.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_set_str(namespace, key, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Write a string value to Non Volatile Storage under namespace, key.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_get_uint8(namespace, key, default)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Return an unsigned 8 bit value from Non Volatile Storage under namespace, key fall back to default if None.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_set_uint8(namespace, key, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Write an unsigned 8 bit value  to Non Volatile Storage under namespace, key.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_get_uint16(namespace, key, default)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Return an unsigned 16 bit value from Non Volatile Storage under namespace, key fall back to default if None.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_set_uint16(namespace, key, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Write an unsigned 16 bit value  to Non Volatile Storage under namespace, key.&lt;br /&gt;
&lt;br /&gt;
More about the [[Projects:Badge/Splash#NVS_settings|Non Volatile Storage namespaces and values]].&lt;br /&gt;
&lt;br /&gt;
==import wifi==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;wifi.init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Connect to the wifi, using NVS  badge, wifi.ssid and badge, wifi.password data.&lt;br /&gt;
&lt;br /&gt;
To wait for wifi connection, try:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;while not wifi.sta_if.isconnected():&lt;br /&gt;
    time.sleep(0.1)&lt;br /&gt;
    pass&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==import ugfx==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import ugfx&lt;br /&gt;
&lt;br /&gt;
ugfx.init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Initialises the [https://ugfx.io/ uGFX] modules for use.&lt;br /&gt;
&lt;br /&gt;
In case you want to unload the ugfx library to clear up memory or something, you can use &amp;lt;code&amp;gt;ugfx.deinit()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Flush===&lt;br /&gt;
&lt;br /&gt;
Since this is a ultra low power bi-stable display, you'll need to flush your buffer to the screen!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.flush()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can select a different way the E-Ink display updates.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.set_lut(lut)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Where the &amp;lt;code&amp;gt;lut&amp;lt;/code&amp;gt; is one of the defined [[Projects:Badge/MicroPython#Constants|constants]] . .&lt;br /&gt;
&lt;br /&gt;
===Primitives===&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.clear(colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
For colours, see [https://wiki.sha2017.org/w/Projects:Badge/MicroPython#Constants constants].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fonts_list()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Gives you a list of usable [https://wiki.sha2017.org/w/Projects:Badge/MicroPython#Constants fonts].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fonts_dump(name)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Dump the contents of the given font, you can write this to flash or use it directly.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fonts_load(dump)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Import the fiven font data from a dump to be used with ugfx.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.get_char_width(char, font)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns the with of a given character, font combination in pixels.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.get_string_width(string, font)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns the with of a given string, font combination in pixels.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.char(x, y, char, font, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws the given character at the position `(x, y)` using the given font and colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.string(x, y, string, font, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws the given string of text at the position `(x, y)` using the given font and colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.string_box(x, y, a, b, str, font, colour, justify)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws the given text in a box at position `(x, y)` with lengths a,b using the given font,  colour and [https://wiki.sha2017.org/w/Projects:Badge/MicroPython#Constants justification].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.pixel(x, y, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a pixel at (x,y) using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.line(x1, y1, x2, y2, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a line from (x1,y1) to (x2,y2) using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.box(x, y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a box from (x,y), with lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.rounded_box(x, y, a, b, radius, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a box from (x,y), with lengths a,b, rounded corners with radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_rounded_box(x, y, a, b, radius, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a box from (x,y), with lengths a,b, rounded corners with radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.area(x, y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill area from (x,y), with lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.thickline(x1, y1, x2, y2, colour, width, round)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a line with a given thickness from (x1,y1) to (x2,y2) using the given colour, with an option to round the ends.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.circle(x, y, r, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a circle having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_circle(x, y, r, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill a circle having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.ellipse(x, y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw an ellipse having a centre point at (x,y), lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_ellipse(x,y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill an ellipse having a centre point at (x,y), lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.arc(x, y, r, angle1, angle2, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw an arc having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_arc(x, y, r, angle1, angle2, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill an arc having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.polygon(x, y, array, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a polygon starting at (x,y), using the array of points, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_polygon(x, y, array, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill a polygon starting at (x,y), using the array of points, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.ugfx_demo(&amp;quot;Hacking&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Expects a string, displays the Still Hacking Anyway sticker 😉&lt;br /&gt;
&lt;br /&gt;
===Input===&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.input_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Needs &amp;lt;code&amp;gt;badge.init()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ugfx.init()&amp;lt;/code&amp;gt; to have ran before it.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.input_attach(button, callback)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The callback has one boolean argument, pressed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.input_attach(ugfx.JOY_UP, lambda pressed: print(pressed))&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
This example attaches a simple print function to the UP button, showing True for press and False for release.&lt;br /&gt;
&lt;br /&gt;
===Constants===&lt;br /&gt;
&lt;br /&gt;
Colours:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.BLACK&lt;br /&gt;
ugfx.WHITE&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Justification:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.justifyLeft&lt;br /&gt;
ugfx.justifyCenter&lt;br /&gt;
ugfx.justifyRight&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.JOY_UP&lt;br /&gt;
ugfx.JOY_DOWN&lt;br /&gt;
ugfx.JOY_LEFT&lt;br /&gt;
ugfx.JOY_RIGHT&lt;br /&gt;
ugfx.BTN_A&lt;br /&gt;
ugfx.BTN_B&lt;br /&gt;
ugfx.BTN_SELECT&lt;br /&gt;
ugfx.BTN_START&lt;br /&gt;
ugfx.BTN_FLASH&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
E-Ink [[Projects:Badge/Documentation/E-Ink#Look_Up_Table_.28LUT.29|LUT]]:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.LUT_FULL&lt;br /&gt;
ugfx.LUT_NORMAL&lt;br /&gt;
ugfx.LUT_FASTER&lt;br /&gt;
ugfx.LUT_FASTEST&lt;br /&gt;
ugfx.GREYSCALE&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GREYSCALE is technically not a lut but a special rendering mode.&lt;br /&gt;
&lt;br /&gt;
===Fonts===&lt;br /&gt;
* Roboto_Regular12&lt;br /&gt;
* Roboto_Regular18&lt;br /&gt;
* Roboto_Regular22&lt;br /&gt;
* Roboto_Black22&lt;br /&gt;
* Roboto_BlackItalic24&lt;br /&gt;
* PermanentMarker22&lt;br /&gt;
* PermanentMarker36&lt;br /&gt;
* pixelade13&lt;br /&gt;
* DejaVuSans20&lt;br /&gt;
* weather42&lt;br /&gt;
&lt;br /&gt;
===Have Fun!!===&lt;br /&gt;
&lt;br /&gt;
Let's get started!!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import badge&lt;br /&gt;
import ugfx&lt;br /&gt;
&lt;br /&gt;
badge.init()&lt;br /&gt;
ugfx.init()&lt;br /&gt;
&lt;br /&gt;
ugfx.clear(ugfx.BLACK)&lt;br /&gt;
&lt;br /&gt;
ugfx.fill_circle(60, 60, 50, ugfx.WHITE);&lt;br /&gt;
ugfx.fill_circle(60, 60, 40, ugfx.BLACK);&lt;br /&gt;
ugfx.fill_circle(60, 60, 30, ugfx.WHITE);&lt;br /&gt;
ugfx.fill_circle(60, 60, 20, ugfx.BLACK);&lt;br /&gt;
ugfx.fill_circle(60, 60, 10, ugfx.WHITE);&lt;br /&gt;
&lt;br /&gt;
ugfx.thickline(1,1,100,100,ugfx.WHITE,10,5)&lt;br /&gt;
ugfx.box(30,30,50,50,ugfx.WHITE)&lt;br /&gt;
&lt;br /&gt;
ugfx.string(150,25,&amp;quot;STILL&amp;quot;,&amp;quot;Roboto_BlackItalic24&amp;quot;,ugfx.WHITE)&lt;br /&gt;
ugfx.string(130,50,&amp;quot;Hacking&amp;quot;,&amp;quot;PermanentMarker22&amp;quot;,ugfx.WHITE)&lt;br /&gt;
len = ugfx.get_string_width(&amp;quot;Hacking&amp;quot;,&amp;quot;PermanentMarker22&amp;quot;)&lt;br /&gt;
ugfx.line(130, 72, 144 + len, 72, ugfx.WHITE)&lt;br /&gt;
ugfx.line(140 + len, 52, 140 + len, 70, ugfx.WHITE)&lt;br /&gt;
ugfx.string(140,75,&amp;quot;Anyway&amp;quot;,&amp;quot;Roboto_BlackItalic24&amp;quot;,ugfx.WHITE)&lt;br /&gt;
&lt;br /&gt;
ugfx.flush()&lt;br /&gt;
&lt;br /&gt;
def render(text, pushed):&lt;br /&gt;
    if(pushed):&lt;br /&gt;
        ugfx.string(100,10,text,&amp;quot;PermanentMarker22&amp;quot;,ugfx.WHITE)&lt;br /&gt;
    else:&lt;br /&gt;
        ugfx.string(100,10,text,&amp;quot;PermanentMarker22&amp;quot;,ugfx.BLACK)&lt;br /&gt;
    ugfx.flush()&lt;br /&gt;
&lt;br /&gt;
ugfx.input_init()&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_UP, lambda pressed: render('UP', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: render('DOWN', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: render('LEFT', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: render('RIGHT', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_A, lambda pressed: render('A', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_B, lambda pressed: render('B', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_START, lambda pressed: render('Start', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_SELECT, lambda pressed: render('Select', pressed))&lt;br /&gt;
&lt;br /&gt;
while True:&lt;br /&gt;
    pass&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pim</name></author>	</entry>

	<entry>
		<id>https://wiki.sha2017.org/index.php?title=Projects:Badge/MicroPython&amp;diff=10468</id>
		<title>Projects:Badge/MicroPython</title>
		<link rel="alternate" type="text/html" href="https://wiki.sha2017.org/index.php?title=Projects:Badge/MicroPython&amp;diff=10468"/>
				<updated>2017-08-04T20:21:16Z</updated>
		
		<summary type="html">&lt;p&gt;Pim: Added clean_repl, per advice Sebastius&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Badgemenu}}&lt;br /&gt;
== MicroPython ==&lt;br /&gt;
===WIP===&lt;br /&gt;
&lt;br /&gt;
Currently a fast moving target, documentation should be up-to-date though . .&lt;br /&gt;
&lt;br /&gt;
Connect to your badge with your favourite serial terminal (e.g. `picocom /dev/ttyUSB0 -b115200`) for a REPL, or start the [[Projects:Badge/Emulator|emulator]].&lt;br /&gt;
&lt;br /&gt;
You can use [[Projects:Badge/ampy|ampy]] or  [[Projects:Badge/mpfshell|mpfshell]] to connect to your badge too.&lt;br /&gt;
&lt;br /&gt;
To be able to start a REPL you need the clean_repl egg from the hatchery: https://badge.sha2017.org/projects/clean_repl . This will restart the badge, starts nothing and makes it possible to use the REPL.&lt;br /&gt;
&lt;br /&gt;
==help()==&lt;br /&gt;
&lt;br /&gt;
This should get you started hacking right away.&lt;br /&gt;
&lt;br /&gt;
==import esp==&lt;br /&gt;
&lt;br /&gt;
This module hosts some of the low-level ESP32 features.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import esp&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtc_get_reset_reason(cpu)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Where CPU is 0 or 1, other values for CPU always return 0.&lt;br /&gt;
&lt;br /&gt;
Returns the [http://esp32.info/docs/esp_idf/html/db/dc1/group__rtc__apis.html#ga826b88529aef76135636c06d408513aa reset reason] of last reset event.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.start_sleeping(miliseconds)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Put the processors to sleep for the given amount of time . .&lt;br /&gt;
&lt;br /&gt;
Reading and writing of RTC memory '''currently doesn't keep contents over deep-sleep!'''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_write(offset, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Sets value at offset.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_read(offset)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns value stored at offset.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_write_string(string, offset = 2)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Sets string value at optional offset.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;esp.rtcmem_read_string(offset = 2)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns string value stored at optional offset.&lt;br /&gt;
&lt;br /&gt;
NB: To set a program for boot run, put in the name at offset two and make sure the values of offset 0 and 1 are not each others inverse ;)&lt;br /&gt;
&lt;br /&gt;
==import badge==&lt;br /&gt;
&lt;br /&gt;
The first thing you would want to do is get the display working, this is currently done by the &amp;lt;code&amp;gt;boot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import badge&lt;br /&gt;
badge.init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise all badge peripherals, this is probably the way you want to start your app.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.eink_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Just init the screen.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.eink_busy()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a &amp;lt;code&amp;gt;boolean&amp;lt;/code&amp;gt; value to indicate eink is currently being flushed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.eink_busy_wait()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Waits for the eink to be flushed, handy to use before you deepsleep.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.power_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise power sensing and related pin states.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.battery_charge_status()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a boolean, true for charging, false for not charging.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.battery_volt_sense()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a value somewhat representing the battery voltage in milivolts ('''needs calibration)'''!&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.usb_volt_sense()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns a value somewhat representing the USB voltage in milivolts ('''needs calibration)'''!&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise power to the LEDs and setup the SPI bus.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_enable()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Initialise power to the LEDs (automagically done by &amp;lt;code&amp;gt;badge.leds.init()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_disable()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Disable power to the LEDs.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.leds_send_data(grbw_values, length)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Stream a given length GRBW values to the LEDs over the SPI bus.&lt;br /&gt;
&lt;br /&gt;
Length should probably be 24 (4 bytes, 6 LEDs) . .&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.vibrator_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Setup the vibrator driver.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.vibrator_activate(pattern)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Send some interesting buzz patterns to the vibrator. .&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_get_str(namespace, key, default)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Return a string from Non Volatile Storage under namespace, key fall back to default if None.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_set_str(namespace, key, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Write a string value to Non Volatile Storage under namespace, key.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_get_uint8(namespace, key, default)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Return an unsigned 8 bit value from Non Volatile Storage under namespace, key fall back to default if None.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_set_uint8(namespace, key, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Write an unsigned 8 bit value  to Non Volatile Storage under namespace, key.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_get_uint16(namespace, key, default)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Return an unsigned 16 bit value from Non Volatile Storage under namespace, key fall back to default if None.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;badge.nvs_set_uint16(namespace, key, value)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Write an unsigned 16 bit value  to Non Volatile Storage under namespace, key.&lt;br /&gt;
&lt;br /&gt;
More about the [[Projects:Badge/Splash#NVS_settings|Non Volatile Storage namespaces and values]].&lt;br /&gt;
&lt;br /&gt;
==import wifi==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;wifi.init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Connect to the wifi, using NVS  badge, wifi.ssid and badge, wifi.password data.&lt;br /&gt;
&lt;br /&gt;
To wait for wifi connection, try:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;while not wifi.sta_if.isconnected():&lt;br /&gt;
    time.sleep(0.1)&lt;br /&gt;
    pass&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==import ugfx==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import ugfx&lt;br /&gt;
&lt;br /&gt;
ugfx.init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Initialises the [https://ugfx.io/ uGFX] modules for use.&lt;br /&gt;
&lt;br /&gt;
In case you want to unload the ugfx library to clear up memory or something, you can use &amp;lt;code&amp;gt;ugfx.deinit()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Flush===&lt;br /&gt;
&lt;br /&gt;
Since this is a ultra low power bi-stable display, you'll need to flush your buffer to the screen!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.flush()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can select a different way the E-Ink display updates.&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.set_lut(lut)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Where the &amp;lt;code&amp;gt;lut&amp;lt;/code&amp;gt; is one of the defined [[Projects:Badge/MicroPython#Constants|constants]] . .&lt;br /&gt;
&lt;br /&gt;
===Primitives===&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.clear(colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
For colours, see [https://wiki.sha2017.org/w/Projects:Badge/MicroPython#Constants constants].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fonts_list()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Gives you a list of usable [https://wiki.sha2017.org/w/Projects:Badge/MicroPython#Constants fonts].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fonts_dump(name)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Dump the contents of the given font, you can write this to flash or use it directly.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fonts_load(dump)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Import the fiven font data from a dump to be used with ugfx.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.get_char_width(char, font)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns the with of a given character, font combination in pixels.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.get_string_width(string, font)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Returns the with of a given string, font combination in pixels.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.char(x, y, char, font, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws the given character at the position `(x, y)` using the given font and colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.string(x, y, string, font, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws the given string of text at the position `(x, y)` using the given font and colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.string_box(x, y, a, b, str, font, colour, justify)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws the given text in a box at position `(x, y)` with lengths a,b using the given font,  colour and [https://wiki.sha2017.org/w/Projects:Badge/MicroPython#Constants justification].&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.pixel(x, y, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a pixel at (x,y) using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.line(x1, y1, x2, y2, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a line from (x1,y1) to (x2,y2) using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.box(x, y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a box from (x,y), with lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.rounded_box(x, y, a, b, radius, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draws a box from (x,y), with lengths a,b, rounded corners with radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_rounded_box(x, y, a, b, radius, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a box from (x,y), with lengths a,b, rounded corners with radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.area(x, y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill area from (x,y), with lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.thickline(x1, y1, x2, y2, colour, width, round)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a line with a given thickness from (x1,y1) to (x2,y2) using the given colour, with an option to round the ends.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.circle(x, y, r, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a circle having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_circle(x, y, r, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill a circle having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.ellipse(x, y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw an ellipse having a centre point at (x,y), lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_ellipse(x,y, a, b, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill an ellipse having a centre point at (x,y), lengths a,b, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.arc(x, y, r, angle1, angle2, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw an arc having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_arc(x, y, r, angle1, angle2, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill an arc having a centre point at (x,y), radius r, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.polygon(x, y, array, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Draw a polygon starting at (x,y), using the array of points, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.fill_polygon(x, y, array, colour)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Fill a polygon starting at (x,y), using the array of points, using the given colour.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.ugfx_demo(&amp;quot;Hacking&amp;quot;)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Expects a string, displays the Still Hacking Anyway sticker 😉&lt;br /&gt;
&lt;br /&gt;
===Input===&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.input_init()&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Needs &amp;lt;code&amp;gt;badge.init()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ugfx.init()&amp;lt;/code&amp;gt; to have ran before it.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.input_attach(button, callback)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
The callback has one boolean argument, pressed.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.input_attach(ugfx.JOY_UP, lambda pressed: print(pressed))&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
This example attaches a simple print function to the UP button, showing True for press and False for release.&lt;br /&gt;
&lt;br /&gt;
===Constants===&lt;br /&gt;
&lt;br /&gt;
Colours:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.BLACK&lt;br /&gt;
ugfx.WHITE&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Justification:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.justifyLeft&lt;br /&gt;
ugfx.justifyCenter&lt;br /&gt;
ugfx.justifyRight&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.JOY_UP&lt;br /&gt;
ugfx.JOY_DOWN&lt;br /&gt;
ugfx.JOY_LEFT&lt;br /&gt;
ugfx.JOY_RIGHT&lt;br /&gt;
ugfx.BTN_A&lt;br /&gt;
ugfx.BTN_B&lt;br /&gt;
ugfx.BTN_SELECT&lt;br /&gt;
ugfx.BTN_START&lt;br /&gt;
ugfx.BTN_FLASH&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
E-Ink [[Projects:Badge/Documentation/E-Ink#Look_Up_Table_.28LUT.29|LUT]]:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;ugfx.LUT_FULL&lt;br /&gt;
ugfx.LUT_NORMAL&lt;br /&gt;
ugfx.LUT_FASTER&lt;br /&gt;
ugfx.LUT_FASTEST&lt;br /&gt;
ugfx.GREYSCALE&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GREYSCALE is technically not a lut but a special rendering mode.&lt;br /&gt;
&lt;br /&gt;
===Fonts===&lt;br /&gt;
* Roboto_Regular12&lt;br /&gt;
* Roboto_Regular18&lt;br /&gt;
* Roboto_Regular22&lt;br /&gt;
* Roboto_Black22&lt;br /&gt;
* Roboto_BlackItalic24&lt;br /&gt;
* PermanentMarker22&lt;br /&gt;
* PermanentMarker36&lt;br /&gt;
* pixelade13&lt;br /&gt;
* DejaVuSans20&lt;br /&gt;
* weather42&lt;br /&gt;
&lt;br /&gt;
===Have Fun!!===&lt;br /&gt;
&lt;br /&gt;
Let's get started!!&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;import badge&lt;br /&gt;
import ugfx&lt;br /&gt;
&lt;br /&gt;
badge.init()&lt;br /&gt;
ugfx.init()&lt;br /&gt;
&lt;br /&gt;
ugfx.clear(ugfx.BLACK)&lt;br /&gt;
&lt;br /&gt;
ugfx.fill_circle(60, 60, 50, ugfx.WHITE);&lt;br /&gt;
ugfx.fill_circle(60, 60, 40, ugfx.BLACK);&lt;br /&gt;
ugfx.fill_circle(60, 60, 30, ugfx.WHITE);&lt;br /&gt;
ugfx.fill_circle(60, 60, 20, ugfx.BLACK);&lt;br /&gt;
ugfx.fill_circle(60, 60, 10, ugfx.WHITE);&lt;br /&gt;
&lt;br /&gt;
ugfx.thickline(1,1,100,100,ugfx.WHITE,10,5)&lt;br /&gt;
ugfx.box(30,30,50,50,ugfx.WHITE)&lt;br /&gt;
&lt;br /&gt;
ugfx.string(150,25,&amp;quot;STILL&amp;quot;,&amp;quot;Roboto_BlackItalic24&amp;quot;,ugfx.WHITE)&lt;br /&gt;
ugfx.string(130,50,&amp;quot;Hacking&amp;quot;,&amp;quot;PermanentMarker22&amp;quot;,ugfx.WHITE)&lt;br /&gt;
len = ugfx.get_string_width(&amp;quot;Hacking&amp;quot;,&amp;quot;PermanentMarker22&amp;quot;)&lt;br /&gt;
ugfx.line(130, 72, 144 + len, 72, ugfx.WHITE)&lt;br /&gt;
ugfx.line(140 + len, 52, 140 + len, 70, ugfx.WHITE)&lt;br /&gt;
ugfx.string(140,75,&amp;quot;Anyway&amp;quot;,&amp;quot;Roboto_BlackItalic24&amp;quot;,ugfx.WHITE)&lt;br /&gt;
&lt;br /&gt;
ugfx.flush()&lt;br /&gt;
&lt;br /&gt;
def render(text, pushed):&lt;br /&gt;
    if(pushed):&lt;br /&gt;
        ugfx.string(100,10,text,&amp;quot;PermanentMarker22&amp;quot;,ugfx.WHITE)&lt;br /&gt;
    else:&lt;br /&gt;
        ugfx.string(100,10,text,&amp;quot;PermanentMarker22&amp;quot;,ugfx.BLACK)&lt;br /&gt;
    ugfx.flush()&lt;br /&gt;
&lt;br /&gt;
ugfx.input_init()&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_UP, lambda pressed: render('UP', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: render('DOWN', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: render('LEFT', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: render('RIGHT', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_A, lambda pressed: render('A', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_B, lambda pressed: render('B', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_START, lambda pressed: render('Start', pressed))&lt;br /&gt;
ugfx.input_attach(ugfx.BTN_SELECT, lambda pressed: render('Select', pressed))&lt;br /&gt;
&lt;br /&gt;
while True:&lt;br /&gt;
    pass&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pim</name></author>	</entry>

	</feed>