Added UART communication.
This commit is contained in:
parent
445c43d7d4
commit
c86ebc681f
|
@ -5,6 +5,12 @@
|
|||
#include <M5Core2.h>
|
||||
#include "icons.cpp" // icons
|
||||
|
||||
// UART communication variables
|
||||
#define RX_PIN 19
|
||||
#define TX_PIN 27
|
||||
String stringReceived = "";
|
||||
int valueReceived = 0;
|
||||
|
||||
// GUI variables
|
||||
int brightnessValue = 1;
|
||||
ButtonColors noDraw = {NODRAW, NODRAW, NODRAW};
|
||||
|
@ -44,6 +50,7 @@ boolean bigPacket = false;
|
|||
|
||||
void setup(){
|
||||
Serial.begin(BAUDRATE);
|
||||
Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); // UART communication
|
||||
M5.begin();
|
||||
M5.Axp.SetLcdVoltage(3150); // Set initial brightness
|
||||
|
||||
|
@ -141,6 +148,19 @@ void loop() {
|
|||
isConnected = false;
|
||||
drawGui(COLOR_MODE);
|
||||
}
|
||||
|
||||
// UART communication
|
||||
if(Serial2.available()){
|
||||
char c = Serial2.read();
|
||||
stringReceived += c;
|
||||
if (stringReceived.length() == 1) {
|
||||
valueReceived = stringReceived.toInt();
|
||||
stringReceived = "";
|
||||
} else {
|
||||
stringReceived = "";
|
||||
}
|
||||
}
|
||||
|
||||
if(! SerialBT.isClosed() && SerialBT.connected()) {
|
||||
if(ReadOneByte() == 170) {
|
||||
if(ReadOneByte() == 170) {
|
||||
|
@ -193,7 +213,24 @@ void loop() {
|
|||
#if !DEBUGOUTPUT
|
||||
// *** Add your code here ***
|
||||
if(bigPacket) {
|
||||
drawGui(COLOR_MODE);
|
||||
drawGui(COLOR_MODE);
|
||||
|
||||
// UART OUTPUT
|
||||
switch (valueReceived) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
Serial2.print(attention);
|
||||
break;
|
||||
case 2:
|
||||
Serial2.print(meditation);
|
||||
break;
|
||||
case 3:
|
||||
Serial2.print(poorQuality);
|
||||
break;
|
||||
}
|
||||
|
||||
// SERIAL OUTPUT
|
||||
Serial.print("Attention: ");
|
||||
Serial.print(attention);
|
||||
Serial.print("\n");
|
||||
|
@ -202,7 +239,7 @@ void loop() {
|
|||
Serial.print("\n");
|
||||
Serial.print("Meditation: ");
|
||||
Serial.print(meditation);
|
||||
Serial.print("\n");
|
||||
Serial.print("\n");
|
||||
}
|
||||
#endif
|
||||
bigPacket = false;
|
||||
|
|
Loading…
Reference in a new issue