lensfrex 3 weeks ago
commit ecf5a1965a
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 3
      .gitignore
  2. 5
      .mpyproject.json
  3. 118
      font.py
  4. 59
      keyboard.py
  5. 169
      main.py
  6. 36
      sensor_dh11.py
  7. 40
      sensor_ds18x20.py
  8. 159
      ssd1306.py

3
.gitignore vendored

@ -0,0 +1,3 @@
.idea/
bin
logs

@ -0,0 +1,5 @@
//This is an automatically generated configuration file.
//Please do not modify or delete it!!!
{
"projectName":"reudsh3"
}

@ -0,0 +1,118 @@
import framebuf
font16 = {
'': framebuf.FrameBuffer1(bytearray([0x00,0x31,0x63,0x06,0x04,0x00,0x7E,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x7E,0x00,0x00,0x00,0x70,0x0F,0x20,0x20,0x3F,0x21,0x21,0x3F,0x21,0x21,0x3F,0x21,0x21,0x3F,0x20,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x00,0xFC,0x24,0x24,0x24,0xF4,0xA4,0xA5,0xA6,0xA4,0xA4,0xF4,0x24,0x24,0x24,0x20,0x18,0x07,0x20,0x22,0x26,0x1A,0x1A,0x1A,0x1A,0x1A,0x16,0x26,0x22,0x20,0x20,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x80,0x80,0x80,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x80,0x80,0x20,0x20,0x3F,0x2A,0x2A,0x2A,0x2A,0x7F,0x62,0x46,0x2A,0x32,0x32,0x2A,0x46,0x40,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x10,0x10,0x10,0x10,0x10,0x10,0x90,0xFF,0x90,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x40,0x60,0x20,0x10,0x08,0x04,0x03,0x00,0x03,0x04,0x18,0x30,0x20,0x40,0x40,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x00,0xC0,0x30,0x18,0x00,0x00,0x00,0xFF,0x00,0x00,0x08,0x30,0xC0,0x80,0x00,0x04,0x03,0x00,0x00,0x20,0x20,0x20,0x20,0x1F,0x00,0x00,0x00,0x00,0x00,0x03,0x06,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x80,0x60,0xFC,0x03,0x04,0x04,0xE4,0xA4,0xA4,0xBF,0xA4,0xA4,0xA4,0xE4,0x04,0x00,0x01,0x00,0x7F,0x00,0x20,0x20,0x3F,0x2A,0x2A,0x2A,0x2A,0x2A,0x2A,0x3F,0x20,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x40,0x42,0x44,0x48,0x50,0x40,0x7F,0x40,0x40,0x50,0x48,0x44,0xC2,0x00,0x00,0x00,0x20,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x7F,0x00,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x04,0xF4,0x94,0x94,0x95,0x96,0x94,0xF4,0x04,0x06,0xF6,0x05,0x04,0xF4,0x04,0x00,0x00,0x3F,0x04,0x04,0x24,0x24,0x24,0x3F,0x00,0x00,0x27,0x20,0x20,0x3F,0x00,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x12,0x0A,0x7E,0x2B,0x2A,0x7A,0x4B,0x7A,0x82,0x5A,0x4E,0x37,0x34,0x5C,0x44,0x00,0x00,0x01,0x01,0x75,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x75,0x01,0x01,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x40,0x58,0x4E,0x47,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x00,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0xFC,0xF8,0xF0,0xF0,0xE0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x3F,0x1F,0x1F,0x0F,0x07,0x07,0x03,0x01,0x01,0x00,0x00,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xE0,0xF0,0xF0,0xF8,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x07,0x07,0x0F,0x1F,0x1F,0x3F,0x7F,0x00,0x00,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0xFC,0xF0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x1C,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1C,0x10,0x00,0x00,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x04,0x1C,0x7C,0xFC,0xFC,0xFC,0xFC,0xFC,0x7C,0x1C,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x1F,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0x0C,0x12,0x12,0x0C,0x00,0xE0,0xF8,0x1C,0x04,0x02,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x08,0x00,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0xE0,0xF8,0x1C,0x04,0x06,0x02,0x02,0x02,0x02,0x02,0x06,0x0C,0x1C,0xF8,0xE0,0x00,0x07,0x1F,0x38,0x30,0x60,0x40,0x40,0x40,0x40,0x40,0x60,0x30,0x18,0x0F,0x07,] ), 16,16),
'': framebuf.FrameBuffer1(bytearray([0x00,0xE0,0xF0,0xF8,0xFC,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFC,0xFC,0xF8,0xF0,0xE0,0x00,0x07,0x1F,0x3F,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x3F,0x3F,0x1F,0x07,] ), 16,16),
'!': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'"': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'#': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'$': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x10,0xF0,0x1E,0x10,0x10,0xF0,0x1E,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0D,0x03,0x01,0x01,0x0D,0x03,0x01,0x01,0x00,0x00,0x00,0x00,] ), 16,16),
'%': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x38,0x7C,0x42,0xFF,0xFF,0x82,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x10,0x7F,0x7F,0x1F,0x0F,0x00,0x00,0x00,0x00,] ), 16,16),
'&': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x3C,0x42,0x42,0x42,0x3C,0x80,0x60,0x10,0x8C,0x82,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x0C,0x02,0x01,0x00,0x0F,0x10,0x10,0x10,0x0F,0x00,0x00,] ), 16,16),
"'": framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x80,0xDC,0x7E,0x62,0x62,0xFE,0x9C,0x00,0x00,0xF0,0xF0,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x10,0x10,0x09,0x0F,0x0E,0x1B,0x10,0x10,0x00,] ), 16,16),
'(': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0x80,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
')': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'*': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x08,0x48,0x28,0x1E,0x28,0x48,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'+': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xF0,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
',': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'-': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'.': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'/': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFC,0x1E,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x78,0x3F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'0': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xF0,0xFC,0x06,0x02,0x02,0x06,0xFC,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x18,0x0F,0x03,0x00,0x00,0x00,] ), 16,16),
'1': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x04,0xFC,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'2': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x04,0x02,0x02,0x82,0xC6,0xFC,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1E,0x13,0x11,0x10,0x10,0x10,0x00,0x00,0x00,0x00,] ), 16,16),
'3': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x04,0x42,0x42,0x42,0x66,0xBE,0x9C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x10,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'4': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x60,0x38,0x0C,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x02,0x02,0x02,0x02,0x1F,0x1F,0x02,0x02,0x00,0x00,] ), 16,16),
'5': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x7E,0x42,0x42,0xC2,0x82,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'6': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xF0,0xF8,0x8C,0x46,0x42,0xC2,0xC2,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'7': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0xC2,0xFA,0x3E,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x1F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'8': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x9C,0xBC,0x62,0x42,0xE2,0xBE,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'9': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x38,0x7C,0xC6,0x82,0x82,0x46,0xFC,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x10,0x10,0x0C,0x0F,0x03,0x00,0x00,0x00,] ), 16,16),
':': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
';': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'<': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xC0,0x40,0x40,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x02,0x06,0x04,0x04,0x0C,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'=': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,] ), 16,16),
'>': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x60,0x40,0x40,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x04,0x04,0x06,0x02,0x03,0x01,0x00,0x00,0x00,0x00,] ), 16,16),
'?': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x04,0x02,0x82,0xC2,0x66,0x3E,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'@': framebuf.FrameBuffer1(bytearray([0x00,0xE0,0x30,0x08,0x04,0xC6,0x22,0x12,0x12,0x12,0xF2,0x04,0x0C,0x18,0xE0,0x00,0x00,0x07,0x18,0x30,0x20,0x47,0x4C,0x48,0x48,0x44,0x4F,0x28,0x08,0x04,0x03,0x00,] ), 16,16),
'A': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0x7C,0x0E,0x1E,0x7C,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x1E,0x07,0x01,0x01,0x01,0x01,0x01,0x07,0x1F,0x18,0x00,0x00,] ), 16,16),
'B': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x42,0x42,0x62,0xBE,0x9C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x10,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'C': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0xE0,0xF8,0x0C,0x04,0x02,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x08,0x00,0x00,0x00,0x00,] ), 16,16),
'D': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xFE,0xFE,0x02,0x02,0x02,0x02,0x04,0x0C,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x10,0x10,0x10,0x10,0x08,0x0C,0x07,0x01,0x00,0x00,] ), 16,16),
'E': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x42,0x42,0x42,0x42,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,] ), 16,16),
'F': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x42,0x42,0x42,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'G': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0xE0,0xF8,0x1C,0x04,0x02,0x02,0x82,0x82,0x82,0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x1F,0x0F,0x00,0x00,0x00,] ), 16,16),
'H': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xFE,0xFE,0x40,0x40,0x40,0x40,0x40,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,] ), 16,16),
'I': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'J': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'K': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0xC0,0xB0,0x18,0x0C,0x06,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x03,0x06,0x0C,0x18,0x10,0x00,0x00,0x00,] ), 16,16),
'L': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,] ), 16,16),
'M': framebuf.FrameBuffer1(bytearray([0x00,0x00,0xFE,0x0E,0x3C,0xF0,0xC0,0x00,0x00,0x00,0xC0,0x70,0x0C,0xFE,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x03,0x0E,0x18,0x0E,0x01,0x00,0x00,0x1F,0x00,0x00,] ), 16,16),
'N': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0xFE,0xFE,0x0E,0x3C,0x70,0xC0,0x00,0x00,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x01,0x07,0x1C,0x1F,0x1F,0x00,0x00,0x00,] ), 16,16),
'O': framebuf.FrameBuffer1(bytearray([0x00,0x00,0xF0,0xF8,0x0C,0x06,0x02,0x02,0x02,0x02,0x06,0x0C,0xF8,0xF0,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x18,0x0C,0x07,0x03,0x00,0x00,] ), 16,16),
'P': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x82,0x82,0x82,0xC6,0x7C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'Q': framebuf.FrameBuffer1(bytearray([0x00,0x00,0xF0,0xF8,0x0C,0x06,0x02,0x02,0x02,0x02,0x06,0x0C,0xF8,0xF0,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x18,0x10,0x10,0x10,0x10,0x18,0x3C,0x67,0x43,0x00,0x00,] ), 16,16),
'R': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x82,0x82,0xC6,0x7E,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x03,0x0E,0x1C,0x10,0x00,0x00,0x00,] ), 16,16),
'S': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x38,0x7C,0x66,0xC2,0x82,0x82,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x10,0x10,0x10,0x19,0x0F,0x0F,0x00,0x00,0x00,] ), 16,16),
'T': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x02,0x02,0x02,0xFE,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'U': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'V': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x06,0x3E,0xF8,0xC0,0x00,0x00,0x80,0xE0,0x7C,0x1E,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0F,0x1E,0x1C,0x0F,0x01,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'W': framebuf.FrameBuffer1(bytearray([0x06,0x7E,0xF8,0x00,0x00,0xC0,0xF8,0x1E,0x1E,0xF8,0xC0,0x00,0x00,0xF0,0x7E,0x06,0x00,0x00,0x07,0x1F,0x1E,0x07,0x00,0x00,0x00,0x00,0x07,0x1E,0x1E,0x07,0x00,0x00,] ), 16,16),
'X': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x02,0x06,0x1C,0x30,0xE0,0xE0,0x38,0x1C,0x06,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x0E,0x03,0x01,0x01,0x07,0x0E,0x18,0x10,0x00,0x00,0x00,] ), 16,16),
'Y': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x02,0x0E,0x3C,0xF0,0xC0,0xC0,0xF0,0x3C,0x0E,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'Z': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x82,0x62,0x32,0x0A,0x06,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x16,0x13,0x11,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,] ), 16,16),
'[': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x80,0x80,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'\\': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x02,0x1C,0x70,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0E,0x38,0x40,0x00,0x00,0x00,0x00,] ), 16,16),
']': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'^': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x80,0x60,0x30,0x0C,0x06,0x1C,0x70,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'_': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'`': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'a': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x20,0x10,0x10,0x90,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x1F,0x11,0x11,0x08,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'b': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xFF,0xFF,0x20,0x10,0x10,0x10,0x30,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x08,0x10,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'c': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0x30,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'd': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xC0,0xE0,0x30,0x10,0x10,0x20,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x08,0x1F,0x1F,0x00,0x00,0x00,0x00,] ), 16,16),
'e': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xC0,0xE0,0x30,0x10,0x10,0x30,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x19,0x11,0x11,0x11,0x09,0x01,0x00,0x00,0x00,0x00,] ), 16,16),
'f': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xFE,0xFF,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'g': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xC0,0xE0,0x30,0x10,0x10,0x20,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x8F,0x18,0x10,0x10,0x88,0xFF,0x7F,0x00,0x00,0x00,0x00,] ), 16,16),
'h': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xFF,0xFF,0x20,0x10,0x10,0x30,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,] ), 16,16),
'i': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF3,0xF3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'j': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF3,0xF3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'k': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x80,0x40,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x01,0x03,0x06,0x0C,0x18,0x10,0x00,0x00,0x00,] ), 16,16),
'l': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'm': framebuf.FrameBuffer1(bytearray([0x00,0xF0,0xF0,0x20,0x10,0x10,0x30,0xF0,0xE0,0x20,0x10,0x10,0xF0,0xE0,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,] ), 16,16),
'n': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xF0,0xF0,0x20,0x10,0x10,0x30,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,] ), 16,16),
'o': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xC0,0xE0,0x30,0x10,0x10,0x10,0x30,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'p': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xF0,0xF0,0x20,0x10,0x10,0x10,0x30,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x08,0x10,0x10,0x10,0x18,0x0F,0x07,0x00,0x00,0x00,] ), 16,16),
'q': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xC0,0xE0,0x30,0x10,0x10,0x20,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x0F,0x18,0x10,0x10,0x08,0xFF,0xFF,0x00,0x00,0x00,0x00,] ), 16,16),
'r': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0x20,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
's': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF0,0x90,0x10,0x10,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x11,0x11,0x13,0x1F,0x0E,0x00,0x00,0x00,0x00,] ), 16,16),
't': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xFE,0xFE,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x10,0x10,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'u': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0xF0,0xF0,0x00,0x00,0x00,0x00,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x18,0x10,0x10,0x08,0x1F,0x1F,0x00,0x00,0x00,0x00,] ), 16,16),
'v': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x30,0xF0,0xC0,0x00,0x00,0xC0,0xF0,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0F,0x1C,0x1C,0x0F,0x01,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'w': framebuf.FrameBuffer1(bytearray([0x00,0x30,0xF0,0xC0,0x00,0x00,0xC0,0xF0,0xE0,0x00,0x00,0x00,0xC0,0x30,0x00,0x00,0x00,0x00,0x01,0x0F,0x1C,0x1C,0x07,0x00,0x00,0x07,0x1C,0x1C,0x07,0x00,0x00,0x00,] ), 16,16),
'x': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x10,0x30,0xE0,0x80,0x80,0xE0,0x30,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x0E,0x03,0x07,0x0E,0x18,0x10,0x00,0x00,0x00,0x00,] ), 16,16),
'y': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x10,0xF0,0xC0,0x00,0x00,0xC0,0xF0,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x87,0xFC,0x1E,0x07,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'z': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x90,0xF0,0x30,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x18,0x1E,0x13,0x11,0x10,0x10,0x10,0x00,0x00,0x00,0x00,] ), 16,16),
'{': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x7E,0x80,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'|': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'}': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x7E,0x01,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
'~': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
' ': framebuf.FrameBuffer1(bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,] ), 16,16),
}

@ -0,0 +1,59 @@
from machine import Pin
# 定义按键
NUM7, NUM8, NUM9, KEY_UP = range(4)
NUM4, NUM5, NUM6, KEY_DOWN = range(4, 8)
NUM1, NUM2, NUM3, KEY_OK = range(8, 12)
NUM0, KEY_L, KEY_R, KEY_CANCEL = range(12, 16)
NO_KEY = -1
# 定义键盘行和列的GPIO引脚
ROW_PINS = [
Pin(33, Pin.OUT),
Pin(34, Pin.OUT),
Pin(35, Pin.OUT),
Pin(36, Pin.OUT),
]
COLUMN_PINS = [
Pin(38, Pin.IN),
Pin(39, Pin.IN),
Pin(40, Pin.IN),
Pin(41, Pin.IN)
]
def init_keys():
# 初始化键盘行
for row in ROW_PINS:
row.value(0)
# 初始化键盘列
for col in COLUMN_PINS:
col.init(mode=Pin.IN)
def read_key():
for r, row in enumerate(ROW_PINS):
row.value(1)
for c, col in enumerate(COLUMN_PINS):
if col.value() == 1:
row.value(0)
return (4 * r) + c
row.value(0)
return NO_KEY
prev_key = NO_KEY
curr_key = NO_KEY
def read_key_on_released():
global prev_key, curr_key
curr_key = read_key()
if prev_key != NO_KEY and curr_key == NO_KEY:
p = prev_key
prev_key = NO_KEY
return p
prev_key = curr_key
return NO_KEY

@ -0,0 +1,169 @@
import time
from machine import Pin, SPI
from time import sleep
dht_pin = Pin(1, Pin.IN)
ds18b20_pin = Pin(3, Pin.IN)
# from sensor_dh11 import Sensor
from sensor_ds18x20 import Sensor
# sensor = Sensor(dht_pin)
sensor = Sensor(ds18b20_pin)
print('sensor ready')
import ssd1306
spi = SPI(2, sck=Pin(12), mosi=Pin(11), miso=Pin(13))
lcd = ssd1306.init_spi(width=128, height=64, spi=spi, dc=Pin(5), res=Pin(8), cs=Pin(10))
print('lcd ready')
import font
lcd.set_font(font.font16)
print('font ready')
curr_temp = 28.0
max_temp = 30
min_temp = 10
import keyboard
keyboard.init_keys()
print('keyboard init ready')
FRAME_TIME = const(41)
FOCUS_ITEM_MIN_TEMP = 0
FOCUS_ITEM_MAX_TEMP = 1
editing = False
focus_item = FOCUS_ITEM_MIN_TEMP
editing_min_temp = min_temp
editing_max_temp = max_temp
def render_frame():
global curr_temp
lcd.font_text(f'当前{curr_temp:>4.1f}', 0, 0)
if editing:
if focus_item == FOCUS_ITEM_MIN_TEMP:
lcd.font_text(f'最小▶{editing_min_temp:>3}', 0, 16)
lcd.font_text(f'最大 {editing_max_temp:>3}', 0, 32)
else:
lcd.font_text(f'最小 {editing_min_temp:>3}', 0, 16)
lcd.font_text(f'最大▶{editing_max_temp:>3}', 0, 32)
if curr_temp >= editing_max_temp or curr_temp <= editing_min_temp:
lcd.font_text(f'警告●', 0, 48)
else:
lcd.font_text(f'警告○', 0, 48)
else:
lcd.font_text(f'最小 {min_temp:>3}', 0, 16)
lcd.font_text(f'最大 {max_temp:>3}', 0, 32)
if curr_temp >= editing_max_temp or curr_temp <= editing_min_temp:
lcd.font_text(f'警告●', 0, 48)
else:
lcd.font_text(f'警告○', 0, 48)
lcd.show()
def edit_value(digit):
if not editing:
return
global focus_item
def edit_min_temp():
global editing_min_temp
val = editing_min_temp * 10 + digit
if val > 99:
val = digit
editing_min_temp = val
def edit_max_temp():
global editing_max_temp
val = editing_max_temp * 10 + digit
if val > 99:
val = digit
editing_max_temp = val
focus_item_cases = {
FOCUS_ITEM_MIN_TEMP: edit_min_temp,
FOCUS_ITEM_MAX_TEMP: edit_max_temp,
}
focus_item_cases.get(focus_item, lambda: None)()
def cancel():
global editing, editing_min_temp, editing_max_temp, min_temp, max_temp
editing = False
editing_min_temp = min_temp
editing_max_temp = max_temp
def switch_focus_item(direction):
if not editing:
return
global focus_item
if direction == -1:
focus_item = FOCUS_ITEM_MIN_TEMP
elif direction == 1:
focus_item = FOCUS_ITEM_MAX_TEMP
def handle_key_event(key):
global editing, focus_item
def ok():
global editing, focus_item, editing_min_temp, editing_max_temp, min_temp, max_temp
if editing:
min_temp = editing_min_temp
max_temp = editing_max_temp
editing = not editing
actions = {
keyboard.KEY_OK: lambda: ok(),
keyboard.KEY_CANCEL: lambda: cancel(),
keyboard.NUM0: lambda: edit_value(0),
keyboard.NUM1: lambda: edit_value(1),
keyboard.NUM2: lambda: edit_value(2),
keyboard.NUM3: lambda: edit_value(3),
keyboard.NUM4: lambda: edit_value(4),
keyboard.NUM5: lambda: edit_value(5),
keyboard.NUM6: lambda: edit_value(6),
keyboard.NUM7: lambda: edit_value(7),
keyboard.NUM8: lambda: edit_value(8),
keyboard.NUM9: lambda: edit_value(9),
keyboard.KEY_UP: lambda: switch_focus_item(-1),
keyboard.KEY_DOWN: lambda: switch_focus_item(1),
keyboard.KEY_L: lambda: switch_focus_item(-1),
keyboard.KEY_R: lambda: switch_focus_item(1)
}
actions.get(key, lambda: None)()
def main():
while True:
prev_frame_start = time.ticks_ms()
global curr_temp
curr_temp = sensor.read()
key = keyboard.read_key_on_released()
if key != keyboard.NO_KEY:
print('key', key, 'released')
handle_key_event(key)
render_frame()
prev_frame_time_cost = time.ticks_diff(time.ticks_ms(), prev_frame_start)
if FRAME_TIME > prev_frame_time_cost:
sleep((FRAME_TIME - prev_frame_time_cost) * 0.001)
if __name__ == "__main__":
main()

@ -0,0 +1,36 @@
import time
import dht
from machine import Pin
SENSOR_READ_PERIOD = const(2)
class Sensor:
last_read_time: int
last_result: tuple[int, int]
sensor: dht.DHT11
def __init__(self, sensor_data_pin: Pin) -> None:
self.sensor = dht.DHT11(sensor_data_pin)
self.last_read_time = time.time()
self.last_result = (0, 0)
def __should_read_data(self) -> bool:
return (time.time() - self.last_read_time) > SENSOR_READ_PERIOD
def read(self) -> tuple[int, int]:
if not self.__should_read_data():
print("should not read data")
return self.last_result
sensor = self.sensor
try:
sensor.measure()
result = (sensor.temperature(), sensor.humidity())
self.last_result = result
except OSError as e:
print("err reading sensor", e)
return self.last_result
return result

@ -0,0 +1,40 @@
from machine import Pin
SENSOR_READ_PERIOD = const(1)
import onewire, ds18x20, time
class Sensor:
last_read_time: int
last_result: int
sensor: ds18x20.DS18X20
rom: Any
def __init__(self, sensor_data_pin: Pin) -> None:
self.last_read_time = time.time()
self.last_result = 28
self.sensor = ds18x20.DS18X20(onewire.OneWire(sensor_data_pin))
roms = self.sensor.scan()
assert len(roms) == 1, "Not (only) one sensor on the bus"
self.rom = roms[0]
def __should_read_data(self) -> bool:
return (time.time() - self.last_read_time) > SENSOR_READ_PERIOD
def read(self) -> int:
if not self.__should_read_data():
return self.last_result
sensor = self.sensor
try:
sensor.convert_temp()
result = sensor.read_temp(self.rom)
self.last_result = result
self.last_read_time = time.time()
except OSError as e:
print("err reading sensor", e)
return self.last_result
return result

@ -0,0 +1,159 @@
# MicroPython SSD1306 OLED driver, I2C and SPI interfaces created by Adafruit
import time
import framebuf
from machine import Pin, SPI
# register definitions
SET_CONTRAST = const(0x81)
SET_ENTIRE_ON = const(0xa4)
SET_NORM_INV = const(0xa6)
SET_DISP = const(0xae)
SET_MEM_ADDR = const(0x20)
SET_COL_ADDR = const(0x21)
SET_PAGE_ADDR = const(0x22)
SET_DISP_START_LINE = const(0x40)
SET_SEG_REMAP = const(0xa0)
SET_MUX_RATIO = const(0xa8)
SET_COM_OUT_DIR = const(0xc0)
SET_DISP_OFFSET = const(0xd3)
SET_COM_PIN_CFG = const(0xda)
SET_DISP_CLK_DIV = const(0xd5)
SET_PRECHARGE = const(0xd9)
SET_VCOM_DESEL = const(0xdb)
SET_CHARGE_PUMP = const(0x8d)
class SSD1306:
framebuf: framebuf.FrameBuffer
font: dict
def __init__(self, width, height, external_vcc):
self.width = width
self.height = height
self.external_vcc = external_vcc
self.pages = self.height // 8
# Note the subclass must initialize self.framebuf to a framebuffer.
# This is necessary because the underlying data buffer is different
# between I2C and SPI implementations (I2C needs an extra byte).
self.poweron()
self.init_display()
def init_display(self):
for cmd in (
SET_DISP | 0x00, # off
# address setting
SET_MEM_ADDR, 0x00, # horizontal
# resolution and layout
SET_DISP_START_LINE | 0x00,
SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0
SET_MUX_RATIO, self.height - 1,
SET_COM_OUT_DIR | 0x08, # scan from COM[N] to COM0
SET_DISP_OFFSET, 0x00,
SET_COM_PIN_CFG, 0x02 if self.height == 32 else 0x12,
# timing and driving scheme
SET_DISP_CLK_DIV, 0x80,
SET_PRECHARGE, 0x22 if self.external_vcc else 0xf1,
SET_VCOM_DESEL, 0x30, # 0.83*Vcc
# display
SET_CONTRAST, 0xff, # maximum
SET_ENTIRE_ON, # output follows RAM contents
SET_NORM_INV, # not inverted
# charge pump
SET_CHARGE_PUMP, 0x10 if self.external_vcc else 0x14,
SET_DISP | 0x01): # on
self.write_cmd(cmd)
self.fill(0)
self.show()
def poweroff(self):
self.write_cmd(SET_DISP | 0x00)
def contrast(self, contrast):
self.write_cmd(SET_CONTRAST)
self.write_cmd(contrast)
def invert(self, invert):
self.write_cmd(SET_NORM_INV | (invert & 1))
def show(self):
x0 = 0
x1 = self.width - 1
if self.width == 64:
# displays with width of 64 pixels are shifted by 32
x0 += 32
x1 += 32
self.write_cmd(SET_COL_ADDR)
self.write_cmd(x0)
self.write_cmd(x1)
self.write_cmd(SET_PAGE_ADDR)
self.write_cmd(0)
self.write_cmd(self.pages - 1)
self.write_framebuf()
def fill(self, col):
self.framebuf.fill(col)
def pixel(self, x, y, col):
self.framebuf.pixel(x, y, col)
def scroll(self, dx, dy):
self.framebuf.scroll(dx, dy)
def text(self, string, x, y, col=1):
self.framebuf.text(string, x, y, col)
def blit(self, fbuf, x, y, key=-1, palette=None):
self.framebuf.blit(fbuf, x, y, key, palette)
def set_font(self, font):
self.font = font
def font_text(self, string, x_axis, y_axis):
idx = 0
for k in string:
buf = self.font[k]
self.framebuf.blit(buf, x_axis + idx * 16, y_axis)
idx += 1
class SSD1306_SPI(SSD1306):
def __init__(self, width, height, spi: SPI, dc: Pin, res: Pin, cs: Pin, external_vcc=False):
self.rate = 10 * 1024 * 1024
dc.init(dc.OUT, value=0)
res.init(res.OUT, value=0)
cs.init(cs.OUT, value=1)
self.spi = spi
self.dc = dc
self.res = res
self.cs = cs
self.buffer = bytearray((height // 8) * width)
self.framebuf = framebuf.FrameBuffer1(self.buffer, width, height)
super().__init__(width, height, external_vcc)
def write_cmd(self, cmd):
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
self.cs.on()
self.dc.off()
self.cs.off()
self.spi.write(bytearray([cmd]))
self.cs.on()
def write_framebuf(self):
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
self.cs.on()
self.dc.on()
self.cs.off()
self.spi.write(self.buffer)
self.cs.on()
def poweron(self):
self.res.on()
time.sleep_ms(1)
self.res.off()
time.sleep_ms(10)
self.res.on()
def init_spi(width, height, spi, dc, res, cs, external_vcc=False) -> SSD1306_SPI:
return SSD1306_SPI(width, height, spi, dc, res, cs, external_vcc)
Loading…
Cancel
Save