Close

Chords

A project log for Playing with MicroPython on the ESP

Instant gratification on the ESP8266 and ESP-32

hari-wigunaHari Wiguna 05/13/2019 at 02:440 Comments

My usual test program whenever I got something that can do graphics.

This is on a Wemos D1 Mini (ESP82666) with their 0.66" 64x48 pixel OLED at I2C 0x3C using GPIO 4 (SDA) and 5 (SCL)

import machine, ssd1306
import math

class chord:
    i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
    oled = ssd1306.SSD1306_I2C(64,48,i2c)
    oled.fill(0)

    nodeCount = 9
    x0 = 64 / 2
    y0 = 48 / 2
    r = 48 / 2
    x = []
    y = []
    for i in range(0, nodeCount):
        a = math.pi * 2 * i / nodeCount
        x.append(int(x0 + math.sin(a) * r))
        y.append(int(y0 + math.cos(a) * r))

    for i in range(0, nodeCount - 1):
        for j in range(i, nodeCount):
            oled.line(x[i], y[i], x[j], y[j], 1)

    oled.show()

SSD1306 OLED Library is no longer supported by AdaFruit, but it worked for me.

Discussions