Skip to content

Instantly share code, notes, and snippets.

@neon-izm
Created October 11, 2020 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neon-izm/3907743f16875858167eedc8de616fd6 to your computer and use it in GitHub Desktop.
Save neon-izm/3907743f16875858167eedc8de616fd6 to your computer and use it in GitHub Desktop.
これを焼いたM5StickCにBT SPPの接続、切断を繰り返すと勝手にloop()内でSerialBTがコケてloopが止まる。
#include <M5StickC.h>
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
/* Set the delay between fresh samples */
#define DELAY_MS (5)
int led = HIGH;
void setup() {
M5.begin();
delay(500);
//BluetoothのMACアドレス取得
uint8_t macBT[6];
esp_read_mac(macBT, ESP_MAC_BT);
char btname[18];
//PC側で確認するときの名前
sprintf(btname, "BTSPP-%02X%02X", macBT[4], macBT[5]);
SerialBT.begin(btname);
pinMode(10, OUTPUT);
digitalWrite(10, led);
}
int encoded = 0;
void loop() {
digitalWrite(10, led);
led = !led;
encoded++;
//数字を取りあえず出しておく
SerialBT.print(encoded);
delay(DELAY_MS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment