Files
M5Stack/M5Stack.cpp
T

64 lines
1.2 KiB
C++
Raw Normal View History

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-03 17:51:24 +08:00
//UART
2017-04-28 21:53:40 +08:00
Serial.begin(115200);
// Beep init
pinMode(BEEP_PIN, OUTPUT);
digitalWrite(BEEP_PIN, 0);
2017-05-02 20:14:40 +08:00
// LED init
pinMode(LED_PIN, OUTPUT);
2017-06-05 09:26:37 +08:00
// TONE
ledcSetup(TONE_PIN_CHANNEL, 0, 8);
ledcAttachPin(SPEAKER_PIN, 0);
2017-04-28 21:53:40 +08:00
// Setup the button with an internal pull-up
2017-05-02 20:14:40 +08:00
pinMode(BUTTON_A_PIN, INPUT_PULLUP);
pinMode(BUTTON_B_PIN, INPUT_PULLUP);
pinMode(BUTTON_C_PIN, INPUT_PULLUP);
2017-04-28 21:53:40 +08:00
2017-05-15 12:19:44 +08:00
// M5 LCD INIT
2017-04-28 21:53:40 +08:00
lcd.begin();
2017-07-16 16:27:27 +08:00
lcd.setBrightness(100);
2017-04-28 21:53:40 +08:00
lcd.fillScreen(BLACK);
lcd.setCursor(0, 0);
lcd.setTextColor(WHITE);
lcd.setTextSize(1);
// m5.lcd.drawPicture(47, 38, 120, 96, gImage_logo);
2017-07-03 17:51:24 +08:00
//TF Card
2017-04-28 21:53:40 +08:00
if(!SD.begin(TFCARD_CS_PIN)) {
Serial.println("Card Mount Failed");
}
}
2017-07-16 16:27:27 +08:00
void M5Stack::update() {
2017-05-15 12:19:44 +08:00
//button
2017-07-16 16:27:27 +08:00
BtnA.read();
BtnB.read();
BtnC.read();
2017-04-28 21:53:40 +08:00
}
2017-07-03 17:51:24 +08:00
/*
* tone
2017-04-28 21:53:40 +08:00
*/
2017-06-05 09:26:37 +08:00
void M5Stack::tone(double freq) {
ledcWriteTone(TONE_PIN_CHANNEL, freq);
}
2017-07-03 17:51:24 +08:00
/*
* noTone
*/
2017-06-05 09:26:37 +08:00
void M5Stack::noTone() {
ledcWriteTone(TONE_PIN_CHANNEL, 0);
digitalWrite(SPEAKER_PIN, 0);
}
2017-04-28 21:53:40 +08:00
M5Stack m5;