M5Stackの液晶右上に無線LANのアンテナを表示する簡単なサンプルスケッチ。
#include <WiFi.h>
#include <M5Stack.h>
const char* ssid = "ssid";
const char* password = "pass";
unsigned long currentMillis;
unsigned long lastupdateMillis = 0;
#define RGB(r,g,b) (int16_t)(b + (g << 5) + (r << 11)) //色0~31 緑は0~63
void wifi_antenna(bool force=false) {
if (currentMillis - lastupdateMillis > 500 || force) {
if (WiFi.status() != WL_CONNECTED) {
M5.Lcd.fillRect(280, 5, 40, 20, RGB(0, 0, 0));
M5.Lcd.fillRect(280, 23, 40, 2, RED);
} else {
long rssi = WiFi.RSSI();
int siglevel;
if (rssi <= -96)
siglevel = 1;
else if (rssi <= -85)
siglevel = 2;
else if (rssi <= -75)
siglevel = 3;
else
siglevel = 4;
M5.Lcd.fillRect(280, 5, 40, 20, RGB(0, 0, 0));
if (siglevel >= 1)
M5.Lcd.fillRect(280, 20, 5, 5, RGB(20, 20, 25));
if (siglevel >= 2)
M5.Lcd.fillRect(290, 15, 5, 10, RGB(20, 20, 27));
if (siglevel >= 3)
M5.Lcd.fillRect(300, 10, 5, 15, RGB(20, 20, 29));
if (siglevel >= 4)
M5.Lcd.fillRect(310, 5, 5, 20, RGB(20, 20, 31));
}
lastupdateMillis = currentMillis;
}
}
void setup()
{
M5.begin();
M5.Lcd.print("Connecting to ");
M5.Lcd.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
M5.Lcd.print("Connected. IP address: ");
M5.Lcd.println(WiFi.localIP());
wifi_antenna(true);
}
void loop() {
currentMillis = millis();
wifi_antenna();
M5.update();
}