Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created September 22, 2021 08:55
Show Gist options
  • Save mamemomonga/3fee48fbaae9ba3f56e4eb263f249cf3 to your computer and use it in GitHub Desktop.
Save mamemomonga/3fee48fbaae9ba3f56e4eb263f249cf3 to your computer and use it in GitHub Desktop.
rduinoとシリアルでエスケープシーケンスをつかった画面更新

Arduinoとシリアルでエスケープシーケンスをつかった画面更新

環境

  • macOS Big Sur
  • Arduino Nano Every
  • Arduino-CLI
  • GNU Make
  • GNU Screen

準備

  • Arduino-CLIでArduino Naneo Everyを使えるようにする
  • Makefile と app/app.ino を設置する
  • make upload serial
  • 終了はCTRL+A,K,Yを順番に押す
// このファイルは app/app.inoに設置
void setup() {
Serial.begin(38400);
Serial.print("\033[?25l"); // カーソルを消す
}
void loop() {
Serial.print("\033[0:0H"); // カーソルを画面の一番上に移動
unsigned long m = millis();
Serial.println(" *** UPTIME ***");
Serial.print(" Milliseconds: ");
Serial.print(m);
Serial.println();
Serial.print(" Seconds: ");
Serial.print(m/1000);
Serial.println();
Serial.println("***************");
delay(10);
}
# シリアルポート
AR_PORT=/dev/cu.usbmodem2211301
# スケッチ
AR_SKETCH=app
# Arduino Nano Every
AR_FQBN=arduino:megaavr:nona4809
upload: build/$(AR_SKETCH).ino.hex
arduino-cli upload -b $(AR_FQBN) -p $(AR_PORT) --input-dir "$(CURDIR)/build"
compile: build/$(AR_SKETCH).ino.hex
serial:
screen $(AR_PORT) 38400 && reset
clean:
rm -rf build
build/$(AR_SKETCH).ino.hex: $(AR_SKETCH)/$(AR_SKETCH).ino
arduino-cli compile -b $(AR_FQBN) --build-path "$(CURDIR)/build" $(AR_SKETCH)
.PHONY: upload compile serial clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment