1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
| #include <M5Stack.h> TFT_eSprite sp = TFT_eSprite(&M5.Lcd);
void Trapezoid(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, uint32_t c) { sp.fillTriangle(x1, y1, x2, y2, x3, y3, c); sp.fillTriangle(x2, y2, x3, y3, x4, y4, c); }
void T_1(int p, uint32_t c) { sp.fillRect(pos(p) + 10, 70, 20, 10, c); } void T_2(int p, uint32_t c) { sp.fillRect(pos(p) + 40, 70, 20, 10, c); }
void T_3(int p, uint32_t c) { sp.fillRect(pos(p), 80, 10, 40, c); } void T_4(int p, uint32_t c) { sp.fillRect(pos(p) + 30, 80, 10, 40, c); } void T_5(int p, uint32_t c) { sp.fillRect(pos(p) + 60, 80, 10, 40, c); }
void T_6(int p, uint32_t c) { sp.fillRect(pos(p) + 10, 120, 20, 10, c); } void T_7(int p, uint32_t c) { sp.fillRect(pos(p) + 40, 120, 20, 10, c); } void T_8(int p, uint32_t c) { sp.fillRect(pos(p), 130, 10, 40, c); } void T_9(int p, uint32_t c) { sp.fillRect(pos(p) + 30, 130, 10, 40, c); } void T_10(int p, uint32_t c) { sp.fillRect(pos(p) + 60, 130, 10, 40, c); }
void T_11(int p, uint32_t c) { sp.fillRect(pos(p) + 10, 170, 20, 10, c); } void T_12(int p, uint32_t c) { sp.fillRect(pos(p) + 40, 170, 20, 10, c); } void TF_Nums(char *timestr, uint32_t c) { TF_Num(0, timestr[0], c); TF_Num(1, timestr[1], c); TF_Num(2, timestr[2], c); TF_Num(3, timestr[3], c); }
void TF_Num(int p, char num, uint32_t c) { switch (num) { case '0': TF_0(p, c); break; case '1': TF_1(p, c); break; case '2': TF_2(p, c); break; case '3': TF_3(p, c); break; case '4': TF_4(p, c); break; case '5': TF_5(p, c); break; case '6': TF_6(p, c); break; case '7': TF_7(p, c); break; case '8': TF_8(p, c); break; case '9': TF_9(p, c); break; } }
void TF_MENU(uint32_t c) { TF_M(0, c); TF_E(1, c); TF_N(2, c); TF_U(3, c); } void TF_BOOT(uint32_t c) { TF_B(0, c); TF_O(1, c); TF_O(2, c); TF_T(3, c); }
int pos(int p) { int offset = 15; return p * 75 + offset; }
void T_13(int p, uint32_t c) { Trapezoid(pos(p) + 11, 82, pos(p) + 21, 82, pos(p) + 19, 118, pos(p) + 29, 118, c); } void T_14(int p, uint32_t c) { Trapezoid(pos(p) + 48, 82, pos(p) + 58, 82, pos(p) + 41, 118, pos(p) + 51, 118, c); } void T_15(int p, uint32_t c) { Trapezoid(pos(p) + 19, 132, pos(p) + 29, 132, pos(p) + 11, 168, pos(p) + 21, 168, c); } void T_16(int p, uint32_t c) { Trapezoid(pos(p) + 41, 132, pos(p) + 51, 132, pos(p) + 49, 168, pos(p) + 59, 168, c); }
void TF_B(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_6(p, c); T_8(p, c); T_11(p, c); T_12(p, c); T_14(p, c); T_16(p, c);
} void TF_O(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_5(p, c); T_8(p, c); T_10(p, c); T_11(p, c); T_12(p, c); } void TF_T(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_4(p, c); T_9(p, c); }
void TF_M(int p, uint32_t c) { T_3(p, c); T_5(p, c); T_8(p, c); T_9(p, c); T_10(p, c); T_13(p, c); T_14(p, c); } void TF_E(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_6(p, c); T_7(p, c); T_8(p, c); T_11(p, c); T_12(p, c); } void TF_N(int p, uint32_t c) { T_3(p, c); T_5(p, c); T_8(p, c); T_10(p, c);
T_13(p, c); T_16(p, c); } void TF_U(int p, uint32_t c) { T_3(p, c); T_5(p, c); T_8(p, c); T_10(p, c); T_11(p, c); T_12(p, c); }
void TF_0(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_5(p, c); T_8(p, c); T_10(p, c); T_11(p, c); T_12(p, c); }
void TF_1(int p, uint32_t c) { T_1(p, c); T_4(p, c); T_9(p, c); T_11(p, c); T_12(p, c); } void TF_2(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_11(p, c); T_12(p, c); T_14(p, c); T_15(p, c); } void TF_3(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_5(p, c); T_7(p, c); T_10(p, c); T_11(p, c); T_12(p, c); } void TF_4(int p, uint32_t c) { T_3(p, c); T_5(p, c); T_6(p, c); T_7(p, c); T_10(p, c); } void TF_5(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_6(p, c); T_7(p, c); T_10(p, c); T_11(p, c); T_12(p, c); } void TF_6(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_6(p, c); T_7(p, c); T_8(p, c); T_10(p, c); T_11(p, c); T_12(p, c); } void TF_7(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_5(p, c); T_10(p, c); } void TF_8(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_5(p, c); T_6(p, c); T_7(p, c); T_8(p, c); T_10(p, c); T_11(p, c); T_12(p, c); } void TF_9(int p, uint32_t c) { T_1(p, c); T_2(p, c); T_3(p, c); T_5(p, c); T_6(p, c); T_7(p, c); T_10(p, c); T_11(p, c); T_12(p, c); } }``` T_*()関数は個別の線を描画する。 TF_*()関数は文字及び、文字列と数字列を表示する。 これで16セグメントの数字列と文字列を4文字M5stackに表示できる。
## アニメーション 位置を動かす、もしくは一定間隔で表示を変えていけばそれはアニメーションになる。
作成したヘンシンブレスのプログラムの起動画面とメニュー画面は以下のようになっている。 (アニメーションとUIの部分だけ抜粋,そして元が汚かったので一部書き直し・・・。) ```c M5stack-Anim.ino #include <M5Stack.h>
int menumode = 0; int menuselect = 0; int count_m = 0;
void setup() { M5.begin(); for (int i = 1; i < 31; i++) { TFT_Boot(i); delay(20); } }
void loop() { M5.update();
if (menumode == 0) { TFT_Menu(count_m, menuselect); if (count_m < 33) { count_m++; }
if (M5.BtnA.wasPressed() ) { menuselect--; if (menuselect < 1) { menuselect = 5; } } else if (M5.BtnB.wasPressed() ) { menuselect++; if (menuselect > 5) { menuselect = 1; } } else if (M5.BtnC.wasPressed()) { if (menuselect != 0) { count_m = 0; menumode = menuselect; } } }
delay(20); }
|