I will make a device that counts the number of new coronavirus contact confirmation applications in the surroundings with M5 Atom Matrix
As in the case of M5 with ESP32 devices such as M5Stack, M5StickC, ESP32 dev kit, you can make anything by changing the display part.
Creating codehttps://twitter.com/ksasao created a sketch to detect the new coronavirus contact confirmation app, so I will refer to that.
It is an application that checks whether the contact confirmation application is enabled
As the flow on the source
Execute pBLEScan->start(scanTime, false)
↓
Count UUIDs because BLEAdvertisedDeviceCallbacks is run for each BLE device
↓
Return from start()
It will be the flow so count the number of specific UUIDs in BLEAdvertisedDeviceCallbacks
Ignore RSSI (field strength?) and display the number including your own device
// Contact confirmation app UUID
const char* uuid = "0000fd6f-0000-1000-8000-00805f9b34fb";
int deviceNum = 0;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
if(advertisedDevice.haveServiceUUID()){
if(strncmp(advertisedDevice.getServiceUUID().toString().c_str(),uuid, 36) == 0){
// If it is the corresponding UUID, set deviceNum to ++
int rssi = advertisedDevice.getRSSI();
Serial.print("RSSI: ");
Serial.println(rssi);
Serial.print("ADDR: ");
Serial.println(advertisedDevice.getAddress().toString().c_str());
Serial.println("Found!");
deviceNum++;
}
}
}
};
void loop() {
deviceNum = 0;
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
pBLEScan->clearResults();
// write screen drawing process
}
Display numbers in MatrixTo display patterns on the Atom Matrix, prepare LED patterns in an array
Use the officially prepared Windows app
GitHub-m5stack/M5Atom: M5Stack Atom Arduino Library
Use Atom pixel tool, You can save it to a file by writing a figure and then executing TOOLS>SAVE
// File URLZ:/0.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_0[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 002 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 003 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
};
Pass this array to M5.dis.Displaybuff() to display it in the LED Matrix
extern const unsigned char image_0[77]; // Array defined in 0.c file
M5.dis.displaybuff((uint8_t*)image_0,0,0);
So make and prepare as many files as there are numbers.Based on the above, I will count how many new coronavirus contact confirmation applications are in the surroundings with M5Atom Matrix
#include <M5Atom.h>
#include <BLEDevice.h>
// Array data of each number 10 or more is displayed as plus
extern const unsigned char image_0[77];
extern const unsigned char image_1[77];
extern const unsigned char image_2[77];
extern const unsigned char image_3[77];
extern const unsigned char image_4[77];
extern const unsigned char image_5[77];
extern const unsigned char image_6[77];
extern const unsigned char image_7[77];
extern const unsigned char image_8[77];
extern const unsigned char image_9[77];
extern const unsigned char image_plus[77];
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 4; //BLE time-out
BLEScan* pBLEScan;
// UUID of contact confirmation app
const char* uuid = "0000fd6f-0000-1000-8000-00805f9b34fb";
int deviceNum = 0;
bool dark = false;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
if(advertisedDevice.haveServiceUUID()){
if(strncmp(advertisedDevice.getServiceUUID().toString().c_str(),uuid, 36) == 0){
int rssi = advertisedDevice.getRSSI();
Serial.print("RSSI: ");
Serial.println(rssi);
Serial.print("ADDR: ");
Serial.println(advertisedDevice.getAddress().toString().c_str());
Serial.println("Found!");
deviceNum++;
}
}
}
};
void Task1(void *pvParameters) {
// If delay() is written in loop(), M5.update() is not executed and the button cannot be taken, so it is multithreaded.
while(1) {
deviceNum = 0;
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
switch (deviceNum) {
case 0:
M5.dis.displaybuff((uint8_t*)image_0,0,0);
break;
case 1:
M5.dis.displaybuff((uint8_t*)image_1,0,0);
break;
case 2:
M5.dis.displaybuff((uint8_t*)image_2,0,0);
break;
case 3:
M5.dis.displaybuff((uint8_t*)image_3,0,0);
break;
case 4:
M5.dis.displaybuff((uint8_t*)image_4,0,0);
break;
case 5:
M5.dis.displaybuff((uint8_t*)image_5,0,0);
break;
case 6:
M5.dis.displaybuff((uint8_t*)image_6,0,0);
break;
case 7:
M5.dis.displaybuff((uint8_t*)image_7,0,0);
break;
case 8:
M5.dis.displaybuff((uint8_t*)image_8,0,0);
break;
case 9:
M5.dis.displaybuff((uint8_t*)image_9,0,0);
break;
default:
M5.dis.displaybuff((uint8_t*)image_plus,0,0);
break;
}
M5.dis.setBrightness(dark ? 3 : 10);
Serial.print("Devices found: ");
Serial.println(deviceNum);
Serial.println("Scan done!");
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
delay(2000); // LED lighting time
M5.dis.clear();
}
}
void setup() {
M5.begin(true, false, true);
Serial.begin(115200);
Serial.println("Scanning...");
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
xTaskCreatePinnedToCore(Task1,"Task1", 4096, NULL, 3, NULL, 1);
}
void loop() {
M5.update();
if ( M5.Btn.wasReleased() ) {
//Press button to change brightness
Serial.printf("brightness=%d",dark ? 3 : 10);
dark = !dark;
}
}
If you experiment outside with a person who modifies Mikumin P's source and displays the number of surroundings, it is so bright and conspicuous that I tried to change the brightness by pressing the button #M5Atom pic.twitter.com/fQr8AuXiTL
— Moke @ Mugii (@coppercele) June 24, 2020
It seems that there were two other than myself when I tried it at the supermarket
// File URLZ:/0.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_0[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 002 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 003 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
};
// File URLZ:/1.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_1[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 002 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
};
// File URLZ:/2.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_2[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 002 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 004 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, //
};
// File URLZ:/3.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_3[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 002 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
};
// File URLZ:/4.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_4[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 002 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
};
// File URLZ:/5.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_5[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 002 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
};
// File URLZ:/Temp/RarSFX0/6.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_6[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 002 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
};
// File URLZ:/Temp/RarSFX0/7.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_7[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, //
/* Line 001 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 002 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, //
};
// File URLZ:/Temp/RarSFX0/8.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_8[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 002 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 003 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
};
// File URLZ:/Temp/RarSFX0/9.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_9[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0xaa,0xff, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 002 */ 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, //
/* Line 003 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0xaa,0xff, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0xaa,0xff, 0x00,0x00,0x00, //
};
// File URLZ:/Temp/RarSFX0/plus.c
// Image Size: width=5,height=5
// Data Size: 77
const unsigned char image_plus[77]=
{
/* width 005 */ 0x05,
/* height 005 */ 0x05,
/* Line 000 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0xff,0x00,0xc4, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 001 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0xff,0x00,0xc4, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 002 */ 0xff,0x00,0xc4, 0xff,0x00,0xc4, 0xff,0x00,0xc4, 0xff,0x00,0xc4, 0xff,0x00,0xc4, //
/* Line 003 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0xff,0x00,0xc4, 0x00,0x00,0x00, 0x00,0x00,0x00, //
/* Line 004 */ 0x00,0x00,0x00, 0x00,0x00,0x00, 0xff,0x00,0xc4, 0x00,0x00,0x00, 0x00,0x00,0x00, //
};
coppercele

Comments
Please log in or sign up to comment.