-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm5stick-paxcounter.ino
37 lines (31 loc) · 953 Bytes
/
m5stick-paxcounter.ino
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
#include <M5StickC.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
int deviceCount = 0;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
deviceCount++;
}
};
void setup() {
M5.begin();
BLEDevice::init("");
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
pBLEScan->start(5);
}
void loop() {
M5.update();
M5.Lcd.setCursor(0, 0);
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setTextFont(2);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(TFT_GREEN, TFT_BLACK);
// Get the battery voltage and calculate the remaining percentage
float voltage = M5.Axp.GetBatVoltage();
int percentage = map(voltage, 3.0, 4.2, 0, 100);
M5.Lcd.printf("Bluetooth: \r\n %d \r\n \r\n Battery: \r\n %d%%", deviceCount, percentage);
delay(1000);
}