#include "mbed.h" Serial pc(USBTX, USBRX); // 温度取得 // このルーチンはダミーです // 環境に合わせて実装して下さい float getTemperature() { static float temperature = 20; static bool up = false; temperature += (rand() % 100 - (up ? 30 : 70)) / 150.0F; up = temperature < 18.5 ? true : (temperature > 21.5 ? false : up); return temperature; } int main() { pc.baud(115200); pc.format(8, Serial::None, 1); pc.printf("\nInit 100, 75, #FFFFFF\n"); pc.printf("Font 1, SANS_SERIF, BOLD, 8\n"); pc.printf("Font 2, SANS_SERIF, BOLD, 4\n"); pc.printf("DrawRect 0, 0, 100, 10, #0000FF, FILL\n"); pc.printf("DrawRect 0, 35, 100, 20, #40FFFF, FILL\n"); pc.printf("DrawRect 1, 1, 98, 73, #0000FF, 2\n"); for (int y = 25; y < 75; y += 10) { pc.printf("DrawLine 0, %d, 100, %d, #0000FF, 0.4\n", y, y); pc.printf("T%d: DrawText %d, 7, %d, 5, 2, #000000\n", y, 20 - (y - 45) / 10, y); } pc.printf("DrawText 温度管理, 50, 5, 4, 1, #FFFFFF\n"); int MAXSIZE = 50; float width = 94.5 / MAXSIZE; float record[MAXSIZE]; int start = MAXSIZE; while (true) { float temperature = getTemperature(); for (int i = 1; i < MAXSIZE; i++) record[i - 1] = record[i]; record[MAXSIZE - 1] = temperature; if (start > 0) start--; pc.printf("WAIT\n"); pc.printf("DrawText %0.2f°C, 95, 11, 2, 1, #FF0000\n", temperature); for (int i = start; i < MAXSIZE; i++) { float y = 45 - (record[i] - 20) * 10; const char *color = record[i] < 19 ? "00BFFF" : (record[i] > 21 ? "FF0000" : "008000"); pc.printf("N%d: DrawRect %f, %f, %f, %f, #%s, FILL\n", i, i * width + 3, y, width - 0.5, 70 - y, color); } for (int y = 25; y < 75; y += 10) pc.printf("SetOrder T%d, Top\n", y); pc.printf("DRAW\n"); // wait(0.2); } }