1 Star 0 Fork 0

vuitech/M5FactoryTest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FactoryTest.ino 25.61 KB
一键复制 编辑 原始数据 按行查看 历史
李辉 提交于 2022-11-08 16:24 +08:00 . 创建初始版本
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
#include <Arduino.h>
#include <M5Stack.h>
#include <stdlib.h>
//#include "FastLED.h"
#include <SD.h>
#include "WiFi.h"
//#include "utility/MPU9250.h"
#define MENUBARH 40
#define TFTW 240//320 // screen width
#define TFTH 320//240 // screen height
#define TFTW2 120//160 // half screen width
#define TFTH2 160//120 // half screen height
//extern const unsigned char gImage_logoM5[];
extern const unsigned char gImage_logo[];
extern const unsigned char m5stack_startup_music[];
extern void FlappyBird();
extern void sensor();
extern void wifi_clock();
extern void imu_test();
extern void mp3_test();
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
unsigned int Flag = 1;
//MPU6887 IMU;
// #define LEDS_PIN 15
// #define LEDS_NUM 10
// CRGB ledsBuff[LEDS_NUM];
void startupLogo() {
static uint8_t brightness, pre_brightness;
uint32_t length = strlen((char *)m5stack_startup_music);
//M5.Lcd.setBrightness(0);
//M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
M5.Lcd.pushImage(0, 0, 240, 320, (uint16_t *)gImage_logo);
for (int i = 0; i < length; i++) {
dacWrite(SPEAKER_PIN, m5stack_startup_music[i] >> 1);
delayMicroseconds(40);
M5.Speaker.end();
/*
brightness = (i / 157);
if (pre_brightness != brightness) {
pre_brightness = brightness;
M5.Lcd.setBrightness(brightness);
}
*/
}
/*
for (int i = 255; i >= 0; i--) {
// M5.Lcd.setBrightness(i);
if (i <= 32) {
dacWrite(SPEAKER_PIN, i);
}
delay(2);
} */
M5.Speaker.end();
M5.Lcd.fillScreen(BLACK);
delay(2000);
}
#define MIC_Unit 34
#define MAX_LEN 240
#define X_OFFSET 0
#define Y_OFFSET 220
#define X_SCALE 1
#define M5STACKFIRE_MICROPHONE_PIN 34
static void draw_waveform() {
static int16_t val_buf[MAX_LEN] = {0};
static int16_t pt = MAX_LEN - 1;
int micValue = analogRead(MIC_Unit);
val_buf[pt] = map((int16_t)(micValue * X_SCALE), 1800, 4095, 0, 40);
if (--pt < 0) {
pt = MAX_LEN - 1;
}
for (int i = 1; i < (MAX_LEN); i++) {
uint16_t now_pt = (pt + i) % (MAX_LEN);
M5.Lcd.drawLine(i + X_OFFSET,
val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET,
i + 1 + X_OFFSET,
val_buf[(now_pt + 2) % MAX_LEN] + Y_OFFSET, TFT_BLACK);
if (i < MAX_LEN - 1) {
M5.Lcd.drawLine(
i + X_OFFSET, val_buf[now_pt] + Y_OFFSET, i + 1 + X_OFFSET,
val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET, TFT_GREEN);
}
}
}
void micphone()
{
while(1){
draw_waveform() ;
if (M5.BtnB.wasPressed()) {
delay(20);
break;;
}
if (M5.BtnA.wasPressed()) {
delay(20);
break;
}
M5.update();
}
}
//File root ;
void printDirectory(File dir, int numTabs) {
dir = SD.open("/");
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
Serial.print("no more files");
entry.close();
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
// TF card test
void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
//digitalWrite(TFT_CS, 1);
M5.Lcd.printf("Listing directory: %s\n", dirname);
// digitalWrite(TFT_CS, 0);
File root = fs.open(dirname);
root = SD.open("/");
// printDirectory(root, 0);
#if 1
if (!root) {
Serial.println("Failed to open directory");
//digitalWrite(TFT_CS, 0);
M5.Lcd.println("Failed to open directory");
//digitalWrite(TFT_CS, 1);
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
// M5.Lcd.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
// digitalWrite(TFT_CS, 0);
M5.Lcd.print(" DIR : ");
Serial.println(file.name());
M5.Lcd.println(file.name());
//digitalWrite(TFT_CS, 1);
if (levels) {
listDir(fs, file.name(), levels - 1);
}
} else {
//digitalWrite(TFT_CS,0);
Serial.print(" FILE: ");
M5.Lcd.print(" FILE: ");
Serial.print(file.name());
M5.Lcd.print(file.name());
Serial.print(" SIZE: ");
M5.Lcd.print(" SIZE: ");
Serial.println(file.size());
M5.Lcd.println(file.size());
//digitalWrite(TFT_CS, 1);
}
file = root.openNextFile();
}
root.close();
#endif
}
void readFile(fs::FS &fs, const char *path) {
Serial.printf("Reading file: %s\n", path);
M5.Lcd.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
M5.Lcd.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
M5.Lcd.print("Read from file: ");
while (file.available()) {
int ch = file.read();
Serial.write(ch);
M5.Lcd.write(ch);
}
}
void writeFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Writing file: %s\n", path);
M5.Lcd.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
M5.Lcd.println("Failed to open file for writing");
return;
}
if (file.print(message)) {
Serial.println("File written");
M5.Lcd.println("File written");
} else {
Serial.println("Write failed");
M5.Lcd.println("Write failed");
}
}
static byte c1;
byte utf8ascii(byte ascii) {
if (ascii < 128) // Standard ASCII-set 0..0x7F handling
{
c1 = 0;
return (ascii);
}
// get previous input
byte last = c1; // get last char
c1 = ascii; // remember actual character
switch (last) // conversion depending on first UTF8-character
{
case 0xC2:
return (ascii);
break;
case 0xC3:
return (ascii | 0xC0);
break;
case 0x82:
if (ascii == 0xAC) return (0x80); // special case Euro-symbol
}
return (0); // otherwise: return zero, if character has to be ignored
}
String utf8ascii(String s) {
String r = "";
char c;
for (int i = 0; i < s.length(); i++) {
c = utf8ascii(s.charAt(i));
if (c != 0) r += c;
}
return r;
}
void wifi_test() {
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("scan start");
M5.Lcd.println("scan start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
M5.Lcd.println("scan done");
if (n == 0) {
Serial.println("no networks found");
M5.Lcd.println("no networks found");
} else {
Serial.print(n);
M5.Lcd.print(n);
Serial.println(" networks found");
M5.Lcd.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
M5.Lcd.print(i + 1);
Serial.print(": ");
M5.Lcd.print(": ");
Serial.print(WiFi.SSID(i).c_str());
M5.Lcd.print(utf8ascii(WiFi.SSID(i).c_str()));
Serial.print(" (");
M5.Lcd.print(" (");
Serial.print(WiFi.RSSI(i));
M5.Lcd.print(WiFi.RSSI(i));
Serial.print(")");
M5.Lcd.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " "
: "*");
M5.Lcd.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " "
: "*");
delay(5);
}
}
Serial.println("");
M5.Lcd.println("");
}
/*
bool gpio_test_flg = 0;
void GPIO_test() {
// uint8_t gpio_table[] = {23,19,18,3,16,21,2,12,15,26,1,17,22,5,13,0,34};
uint8_t gpio_table[] = {12,2,21,16,3,18,19,23,15,0,13,5,22,17,1,26,25};
// while(1)
{
for (int i = 0; i<=sizeof(gpio_table) / sizeof(gpio_table[0]); i++) {
pinMode(gpio_table[i], OUTPUT);
}
for(int i=0; i<=sizeof(gpio_table)/sizeof(gpio_table[0]); i++) {
digitalWrite(gpio_table[i], 1);
delay(50);
digitalWrite(gpio_table[i], 0);
delay(50);
digitalWrite(gpio_table[i], 1);
delay(50);
digitalWrite(gpio_table[i], 0);
delay(50);
}
}
}
void adc_test() {
int count = 10;
pinMode(35, INPUT);
pinMode(36, INPUT);
pinMode(34, INPUT);
M5.Lcd.fillScreen(BLACK);
while(count--) {
M5.Lcd.setCursor(0, 10);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setTextSize(2);
M5.Lcd.printf("ADC35:%d\r\nADC36:%d\r\nADC34:%d\r\n", analogRead(35),
analogRead(36), analogRead(34)); delay(500);
}
}
*/
unsigned long testLines(uint16_t color) {
unsigned long start, t;
int x1, y1, x2, y2, w = M5.Lcd.width(), h = M5.Lcd.height();
M5.Lcd.fillScreen(TFT_BLACK);
x1 = y1 = 0;
y2 = h - 1;
start = micros();
for (x2 = 0; x2 < w; x2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
x2 = w - 1;
for (y2 = 0; y2 < h; y2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
t = micros() - start; // fillScreen doesn't count against timing
M5.Lcd.fillScreen(TFT_BLACK);
x1 = w - 1;
y1 = 0;
y2 = h - 1;
start = micros();
for (x2 = 0; x2 < w; x2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
x2 = 0;
for (y2 = 0; y2 < h; y2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
t += micros() - start;
M5.Lcd.fillScreen(TFT_BLACK);
x1 = 0;
y1 = h - 1;
y2 = 0;
start = micros();
for (x2 = 0; x2 < w; x2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
x2 = w - 1;
for (y2 = 0; y2 < h; y2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
t += micros() - start;
M5.Lcd.fillScreen(TFT_BLACK);
x1 = w - 1;
y1 = h - 1;
y2 = 0;
start = micros();
for (x2 = 0; x2 < w; x2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
x2 = 0;
for (y2 = 0; y2 < h; y2 += 6) M5.Lcd.drawLine(x1, y1, x2, y2, color);
return micros() - start;
}
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
unsigned long start;
int x, y, w = M5.Lcd.width(), h = M5.Lcd.height();
M5.Lcd.fillScreen(TFT_BLACK);
start = micros();
for (y = 0; y < h; y += 5) M5.Lcd.drawFastHLine(0, y, w, color1);
for (x = 0; x < w; x += 5) M5.Lcd.drawFastVLine(x, 0, h, color2);
return micros() - start;
}
unsigned long testRects(uint16_t color) {
unsigned long start;
int n, i, i2, cx = M5.Lcd.width() / 2, cy = M5.Lcd.height() / 2;
M5.Lcd.fillScreen(TFT_BLACK);
n = min(M5.Lcd.width(), M5.Lcd.height());
start = micros();
for (i = 2; i < n; i += 6) {
i2 = i / 2;
M5.Lcd.drawRect(cx - i2, cy - i2, i, i, color);
}
return micros() - start;
}
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
unsigned long start, t = 0;
int n, i, i2, cx = M5.Lcd.width() / 2 - 1, cy = M5.Lcd.height() / 2 - 1;
M5.Lcd.fillScreen(TFT_BLACK);
n = min(M5.Lcd.width(), M5.Lcd.height());
for (i = n - 1; i > 0; i -= 6) {
i2 = i / 2;
start = micros();
M5.Lcd.fillRect(cx - i2, cy - i2, i, i, color1);
t += micros() - start;
// Outlines are not included in timing results
M5.Lcd.drawRect(cx - i2, cy - i2, i, i, color2);
}
return t;
}
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
unsigned long start;
int x, y, w = M5.Lcd.width(), h = M5.Lcd.height(), r2 = radius * 2;
M5.Lcd.fillScreen(TFT_BLACK);
start = micros();
for (x = radius; x < w; x += r2) {
for (y = radius; y < h; y += r2) {
M5.Lcd.fillCircle(x, y, radius, color);
}
}
return micros() - start;
}
unsigned long testCircles(uint8_t radius, uint16_t color) {
unsigned long start;
int x, y, r2 = radius * 2, w = M5.Lcd.width() + radius,
h = M5.Lcd.height() + radius;
// Screen is not cleared for this one -- this is
// intentional and does not affect the reported time.
start = micros();
for (x = 0; x < w; x += r2) {
for (y = 0; y < h; y += r2) {
M5.Lcd.drawCircle(x, y, radius, color);
}
}
return micros() - start;
}
unsigned long testTriangles() {
unsigned long start;
int n, i, cx = M5.Lcd.width() / 2 - 1, cy = M5.Lcd.height() / 2 - 1;
M5.Lcd.fillScreen(TFT_BLACK);
n = min(cx, cy);
start = micros();
for (i = 0; i < n; i += 5) {
M5.Lcd.drawTriangle(cx, cy - i, // peak
cx - i, cy + i, // bottom left
cx + i, cy + i, // bottom right
M5.Lcd.color565(0, 0, i));
}
return micros() - start;
}
unsigned long testFilledTriangles() {
unsigned long start, t = 0;
int i, cx = M5.Lcd.width() / 2 - 1, cy = M5.Lcd.height() / 2 - 1;
M5.Lcd.fillScreen(TFT_BLACK);
start = micros();
for (i = min(cx, cy); i > 10; i -= 5) {
start = micros();
M5.Lcd.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
M5.Lcd.color565(0, i, i));
t += micros() - start;
M5.Lcd.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
M5.Lcd.color565(i, i, 0));
}
return t;
}
unsigned long testRoundRects() {
unsigned long start;
int w, i, i2, cx = M5.Lcd.width() / 2 - 1, cy = M5.Lcd.height() / 2 - 1;
M5.Lcd.fillScreen(TFT_BLACK);
w = min(M5.Lcd.width(), M5.Lcd.height());
start = micros();
for (i = 0; i < w; i += 6) {
i2 = i / 2;
M5.Lcd.drawRoundRect(cx - i2, cy - i2, i, i, i / 8,
M5.Lcd.color565(i, 0, 0));
}
return micros() - start;
}
unsigned long testFilledRoundRects() {
unsigned long start;
int i, i2, cx = M5.Lcd.width() / 2 - 1, cy = M5.Lcd.height() / 2 - 1;
M5.Lcd.fillScreen(TFT_BLACK);
start = micros();
for (i = min(M5.Lcd.width(), M5.Lcd.height()); i > 20; i -= 6) {
i2 = i / 2;
M5.Lcd.fillRoundRect(cx - i2, cy - i2, i, i, i / 8,
M5.Lcd.color565(0, i, 0));
}
return micros() - start;
}
// void ledBar()
// {
// FastLED.addLeds<SK6812, LEDS_PIN>(ledsBuff, LEDS_NUM);
// for (int i = 0; i < LEDS_NUM; i++) {
// ledsBuff[i].setRGB(20, 20, 20);
// }
// FastLED.show();
// }
// the setup routine runs once when M5Stack starts up
void show_desktop(){
//绘制桌面
M5.Lcd.setBrightness(100);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.drawFastHLine(0, MENUBARH, TFTW, BLUE);
M5.Lcd.drawFastHLine(0, 0, TFTW, BLUE);
M5.Lcd.drawLine(0, 0, 0, MENUBARH, BLUE);
M5.Lcd.drawLine(TFTW-1, 0, 0, MENUBARH, BLUE);
// M5.Lcd.drawFastHLine(0, MENUBARH, TFTW, BLUE);
// M5.Lcd.drawFastHLine(0, MENUBARH, TFTW, BLUE);
M5.Lcd.fillRect(1, 1, TFTW, MENUBARH-1, WHITE);
M5.Lcd.fillTriangle(TFTW2,5 , TFTW2-20, MENUBARH-5, TFTW2+20, MENUBARH-5, BLUE);
//M5.Lcd.fillRect(0, TFTH -GAMEH + 1, TFTW, GRASSH, GRASSCOL);
M5.Lcd.drawFastHLine(0, TFTH -MENUBARH, TFTW, BLUE);
M5.Lcd.drawFastHLine(0, TFTH-1, TFTW, BLUE);
M5.Lcd.drawLine(0,TFTH -MENUBARH, 0,TFTH-1, BLUE);
M5.Lcd.drawLine(TFTW-1, TFTH -MENUBARH, TFTW-1, TFTH -1, BLUE);
M5.Lcd.fillRect(1, TFTH -MENUBARH+ 1, TFTW-2, MENUBARH-2, WHITE);
M5.Lcd.fillTriangle(TFTW2, TFTH -5 , TFTW2-20, TFTH -MENUBARH +5, TFTW2+20, TFTH -MENUBARH+5, BLUE);
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(20, MENUBARH+10);
M5.Lcd.fillRect(20, MENUBARH+10, TFTW, MENUBARH-1, BLACK);
// M5.Lcd.printf(" ");
// M5.Lcd.printf("Display Test!");
switch(Flag){
case 1: M5.Lcd.printf("%d.FlappyBird Game",Flag);break;
case 2: M5.Lcd.printf("%d.Display Test",Flag);break;
case 3: M5.Lcd.printf("%d.Sensor Test",Flag);break;
case 4: M5.Lcd.printf("%d.MPU6887 Test",Flag);break;
case 5: M5.Lcd.printf("%d.Micphone Test",Flag);break;
case 6: M5.Lcd.printf("%d.Music Test",Flag);break;
case 7: M5.Lcd.printf("%d.Wifi Test",Flag);break;
}
}
void lcd_test(){
// Lcd display
M5.Lcd.setBrightness(100);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(80, 150);
M5.Lcd.setTextColor(RED);
M5.Lcd.setTextSize(2);
M5.Lcd.printf("start...!");
delay(500);
M5.Lcd.fillScreen(WHITE);
delay(150);
M5.Lcd.fillScreen(RED);
delay(150);
M5.Lcd.fillScreen(GREEN);
delay(150);
M5.Lcd.fillScreen(BLUE);
delay(150);
M5.Lcd.fillScreen(BLACK);
delay(150);
// draw graphic
yield();
Serial.print(F("Lines "));
yield();
Serial.println(testLines(TFT_CYAN));
// total+=testLines(TFT_CYAN);
// delay(500);
yield();
Serial.print(F("Horiz/Vert Lines "));
yield();
Serial.println(testFastLines(TFT_RED, TFT_BLUE));
// total+=testFastLines(TFT_RED, TFT_BLUE);
// delay(500);
yield();
Serial.print(F("Rectangles (outline) "));
yield();
Serial.println(testRects(TFT_GREEN));
// total+=testRects(TFT_GREEN);
// delay(500);
yield();
Serial.print(F("Rectangles (filled) "));
yield();
Serial.println(testFilledRects(TFT_YELLOW, TFT_MAGENTA));
// total+=testFilledRects(TFT_YELLOW, TFT_MAGENTA);
// delay(500);
yield();
Serial.print(F("Circles (filled) "));
yield();
Serial.println(testFilledCircles(10, TFT_MAGENTA));
// total+= testFilledCircles(10, TFT_MAGENTA);
yield();
Serial.print(F("Circles (outline) "));
yield();
Serial.println(testCircles(10, TFT_WHITE));
// total+=testCircles(10, TFT_WHITE);
// delay(500);
yield();
Serial.print(F("Triangles (outline) "));
yield();
Serial.println(testTriangles());
// total+=testTriangles();
// delay(500);
yield();
Serial.print(F("Triangles (filled) "));
yield();
Serial.println(testFilledTriangles());
// total += testFilledTriangles();
// delay(500);
yield();
Serial.print(F("Rounded rects (outline) "));
yield();
Serial.println(testRoundRects());
// total+=testRoundRects();
// delay(500);
yield();
Serial.print(F("Rounded rects (filled) "));
yield();
Serial.println(testFilledRoundRects());
// total+=testFilledRoundRects();
// delay(500);
yield();
Serial.println(F("Done!"));
yield();
// rand draw
int i = 250;
while (--i) {
M5.Lcd.fillTriangle(
random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1),
random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1),
random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1),
random(0xfffe));
}
for (int i = 255; i >= 0; i--) {
M5.Lcd.setBrightness(i);
delay(2);
}
}
// TF card test
void tf_test(){
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 80);
M5.Lcd.printf("TF card test:\r\n");
//digitalWrite(TFT_CS, 0);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
/**/
Serial.println("initialization done.");
uint8_t cardType =SD.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if(cardType == CARD_MMC){
Serial.println("MMC");
} else if(cardType == CARD_SD){
Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
listDir(SD, "/", 0);
// writeFile(SD, "/hello.txt", "Hello world");
// readFile(SD, "/hello.txt");
while(1){
if(M5.BtnA.pressedFor(1000, 200)|| M5.BtnB.pressedFor(1000, 200))
{
// SD.begin(TFCARD_CS_PIN, SPI, 40000000);
//digitalWrite(TFCARD_CS_PIN,0);
// digitalWrite(TFT_CS, 1);
// M5.Lcd.begin();
// SD.begin(TFCARD_CS_PIN, SPI, 40000000);
// M5.begin();
SD.end();
M5.Lcd.begin();
break;
}
M5.update();
}
}
void buttons_test() {
int static event = 0;
if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) {
// M5.Lcd.printf("A");
Serial.printf("A");
Flag =Flag+1;
if(Flag >7)
Flag = 7;
//Serial.printf("flag=%d",Flag);
event = 1;
}
if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) {
// M5.Lcd.printf("B");
Flag =Flag-1;
if(Flag <1)
Flag = 1;
// Serial.printf("flag=%d",Flag);
event = 1;
}
/*
if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) {
M5.Lcd.printf("C");
Serial.printf("C");
}
*/
if(event){
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(20, MENUBARH+10);
M5.Lcd.fillRect(20, MENUBARH+10, TFTW, MENUBARH-1, BLACK);
// M5.Lcd.printf(" ");
// M5.Lcd.printf("Display Test!");
switch(Flag){
case 1: M5.Lcd.printf("%d.FlappyBird Game",Flag);delay(500);FlappyBird();show_desktop();break;
case 2: M5.Lcd.printf("%d.Display Test",Flag);delay(500);lcd_test();show_desktop();break;
case 3: M5.Lcd.printf("%d.Sensor Test",Flag);delay(500);sensor();show_desktop();break; //
case 4: M5.Lcd.printf("%d.MPU6887 Test",Flag);delay(500);imu_test();show_desktop();break;
case 5: M5.Lcd.printf("%d.Micphone Test",Flag);delay(500);micphone();show_desktop();break;
case 6: M5.Lcd.printf("%d.Music Test",Flag);delay(500);show_desktop();break; //mp3_test;
case 7: M5.Lcd.printf("%d.Wifi Clock",Flag);delay(500);wifi_clock();show_desktop();break;
}
// delay(100);
// Flag = 0;
event = 0;
}
}
void setup() {
// gpio test
// pinMode(BUTTON_A_PIN, INPUT_PULLUP);
// if(digitalRead(BUTTON_A_PIN) == 0) {
// gpio_test_flg = 1;
// }
// if (gpio_test_flg) {
// GPIO_test();
// }
// initialize the M5Stack object
M5.begin();
/*
Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project
*/
// M5.Power.begin();
M5.Lcd.setRotation(0);
// dac test
// if (gpio_test_flg)
// {
// adc_test();
// }
startupLogo();
//ledBar();
// Wire.begin();
show_desktop();
//M5.Lcd.fillRect(0, TFTH -GAMEH + 1, TFTW, GRASSH, GRASSCOL);
// delay(10000);
// grass and stripe
// M5.Lcd.fillRect(0, TFTH -GAMEH + 1, TFTW2, GRASSH, GRASSCOL);
// Flag =4;
#if 0
// wifi test
M5.Lcd.setCursor(0, 10);
M5.Lcd.fillScreen(BLACK);
for (int i = 0; i < 200; i++) {
M5.Lcd.setBrightness(i);
delay(2);
}
byte c = IMU.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
Serial.print("MPU9250 ");
Serial.print("I AM ");
Serial.print(c, HEX);
Serial.print(" I should be ");
Serial.println(0x71, HEX);
Serial.println("");
M5.Lcd.setCursor(20, 0);
M5.Lcd.print("MPU9250");
M5.Lcd.setCursor(0, 10);
M5.Lcd.print("I AM");
M5.Lcd.setCursor(0, 20);
M5.Lcd.print(c, HEX);
M5.Lcd.setCursor(0, 30);
M5.Lcd.print("I Should Be");
M5.Lcd.setCursor(0, 40);
M5.Lcd.println(0x71, HEX);
M5.Lcd.println();
delay(100);
IMU.initMPU9250();
// Initialize device for active mode read of acclerometer, gyroscope, and
// temperature
Serial.println("MPU9250 initialized for active data mode....");
// Read the WHO_AM_I register of the magnetometer, this is a good test of
// communication
byte d = IMU.readByte(AK8963_ADDRESS, WHO_AM_I_AK8963);
Serial.print("AK8963 ");
Serial.print("I AM ");
Serial.print(d, HEX);
Serial.print(" I should be ");
Serial.println(0x48, HEX);
// M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(20, 100);
M5.Lcd.print("AK8963");
M5.Lcd.setCursor(0, 110);
M5.Lcd.print("I AM");
M5.Lcd.setCursor(0, 120);
M5.Lcd.print(d, HEX);
M5.Lcd.setCursor(0, 130);
M5.Lcd.print("I Should Be");
M5.Lcd.setCursor(0, 140);
M5.Lcd.print(0x48, HEX);
delay(1000);
M5.Lcd.setCursor(0, 0);
M5.Lcd.println("wifi test:");
M5.Lcd.fillScreen(BLACK);
wifi_test();
delay(2000);
// TF card test
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 10);
M5.Lcd.printf("TF card test:\r\n");
// digitalWrite(TFT_CS, 1);
listDir(SD, "/", 0);
writeFile(SD, "/hello.txt", "Hello world");
readFile(SD, "/hello.txt");
// Button test
M5.Lcd.println();
M5.Lcd.println();
M5.Lcd.print("buttons Test:");
M5.Lcd.setTextColor(RED);
#endif
}
// the loop routine runs over and over again forever
void loop() {
buttons_test();
M5.update();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/vuitech/FactoryTest.git
git@gitee.com:vuitech/FactoryTest.git
vuitech
FactoryTest
M5FactoryTest
master

搜索帮助