2017-04-28 21:53:40 +08:00
|
|
|
// Copyright (c) M5Stack. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
#include "M5Stack.h"
|
|
|
|
|
|
2017-07-16 16:27:27 +08:00
|
|
|
void M5Stack::begin() {
|
2017-07-18 18:27:56 +08:00
|
|
|
|
2017-07-20 17:53:07 +08:00
|
|
|
// UART
|
2017-07-18 18:27:56 +08:00
|
|
|
Serial.begin(115200);
|
2017-07-19 18:42:30 +08:00
|
|
|
Serial.flush();
|
|
|
|
|
Serial.println("M5Stack init...");
|
2017-04-28 21:53:40 +08:00
|
|
|
|
2017-07-18 18:27:56 +08:00
|
|
|
// TONE
|
|
|
|
|
Speaker.begin();
|
2017-04-28 21:53:40 +08:00
|
|
|
|
2017-07-18 18:27:56 +08:00
|
|
|
// Setup the button with an internal pull-up
|
|
|
|
|
pinMode(BUTTON_A_PIN, INPUT_PULLUP);
|
|
|
|
|
pinMode(BUTTON_B_PIN, INPUT_PULLUP);
|
|
|
|
|
pinMode(BUTTON_C_PIN, INPUT_PULLUP);
|
2017-06-05 09:26:37 +08:00
|
|
|
|
2017-07-20 17:53:07 +08:00
|
|
|
// TF Card
|
|
|
|
|
SD.begin(TFCARD_CS_PIN);
|
2017-07-19 18:42:30 +08:00
|
|
|
|
|
|
|
|
// M5 LCD INIT
|
|
|
|
|
Lcd.begin();
|
|
|
|
|
Lcd.fillScreen(BLACK);
|
|
|
|
|
Lcd.setCursor(0, 0);
|
|
|
|
|
Lcd.setTextColor(WHITE);
|
|
|
|
|
Lcd.setTextSize(1);
|
|
|
|
|
Lcd.setBrightness(80);
|
2017-04-28 21:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2017-07-16 16:27:27 +08:00
|
|
|
void M5Stack::update() {
|
2017-04-28 21:53:40 +08:00
|
|
|
|
2017-07-18 18:27:56 +08:00
|
|
|
//Button update
|
|
|
|
|
BtnA.read();
|
|
|
|
|
BtnB.read();
|
|
|
|
|
BtnC.read();
|
2017-06-05 09:26:37 +08:00
|
|
|
|
2017-07-18 18:27:56 +08:00
|
|
|
//Speaker update
|
|
|
|
|
Speaker.update();
|
2017-06-05 09:26:37 +08:00
|
|
|
}
|
|
|
|
|
|
2017-08-09 14:49:26 +08:00
|
|
|
void M5Stack::startupLogo() {
|
|
|
|
|
static uint8_t brightness, pre_brightness;
|
|
|
|
|
uint32_t length = strlen((char*)m5stack_startup_music);
|
|
|
|
|
Lcd.setBrightness(0);
|
|
|
|
|
Lcd.drawBitmap(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
|
2017-08-10 11:56:43 +08:00
|
|
|
for(int i=0; i<length; i++) {
|
|
|
|
|
dacWrite(SPEAKER_PIN, m5stack_startup_music[i]>>2);
|
|
|
|
|
delayMicroseconds(40);
|
|
|
|
|
brightness = (i/157);
|
|
|
|
|
if(pre_brightness != brightness) {
|
|
|
|
|
pre_brightness = brightness;
|
|
|
|
|
Lcd.setBrightness(brightness);
|
2017-08-09 14:49:26 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i=255; i>=0; i--) {
|
|
|
|
|
lcd.setBrightness(i);
|
2017-08-10 11:56:43 +08:00
|
|
|
if(i<=32) {
|
|
|
|
|
dacWrite(SPEAKER_PIN, i);
|
|
|
|
|
}
|
2017-08-09 14:49:26 +08:00
|
|
|
delay(2);
|
|
|
|
|
}
|
2017-08-10 11:56:43 +08:00
|
|
|
|
2017-08-09 14:49:26 +08:00
|
|
|
Lcd.fillScreen(BLACK);
|
2017-08-10 11:56:43 +08:00
|
|
|
delay(800);
|
2017-08-09 14:49:26 +08:00
|
|
|
for(int i=0; i>=100; i++) {
|
|
|
|
|
Lcd.setBrightness(i);
|
|
|
|
|
delay(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-28 21:53:40 +08:00
|
|
|
M5Stack m5;
|