|
| 1 | + |
| 2 | +/* This demo is for LASER.TX and LASER.RX, utilized UART for transmittion and reception of |
| 3 | + laser signals. In order to get the result of this demo, you will need to connect LASER.TX |
| 4 | + and LASER.RX with PORTC(blue) respectively onto two different M5Cores with M5GO bases on |
| 5 | + bottom. Then flash the demo into both M5Core device. |
| 6 | +
|
| 7 | + When testing the demo, you need to point the TX unit to RX, and press the button TX connected |
| 8 | + device. RX connected device will reponse with a display,and will show what is received . |
| 9 | +
|
| 10 | + See this link for more detals: https://m5stack.oss-cn-shenzhen.aliyuncs.com/EasyLoader/Unit/LASER/EasyLoader_LASER_RX.exe |
| 11 | + */ |
| 12 | + |
| 13 | +#include <M5Stack.h> |
| 14 | + |
| 15 | +char ch; |
| 16 | +// serial 2 write and read |
| 17 | +//#define RX |
| 18 | +void setup() { |
| 19 | + |
| 20 | + M5.begin(); |
| 21 | + |
| 22 | + Serial.begin(115200); |
| 23 | + |
| 24 | + // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert) |
| 25 | + Serial2.begin(9600, SERIAL_8N1, 16, 17); |
| 26 | + pinMode(5, OUTPUT); |
| 27 | + digitalWrite(5, 1); |
| 28 | + |
| 29 | + M5.Lcd.setTextSize(4); |
| 30 | + M5.Lcd.setTextColor(GREEN); |
| 31 | + M5.Lcd.setCursor(60, 50); |
| 32 | +#ifdef RX |
| 33 | + M5.Lcd.print("LASER RX"); |
| 34 | +#elif defined TX |
| 35 | + M5.Lcd.print("LASER TX"); |
| 36 | +#else |
| 37 | + M5.Lcd.setCursor(30, 50); |
| 38 | + M5.Lcd.print("LASER TX/RX"); |
| 39 | + M5.Lcd.setCursor(50, 200); |
| 40 | + M5.Lcd.print('A'); |
| 41 | + M5.Lcd.setCursor(150, 200); |
| 42 | + M5.Lcd.print('B'); |
| 43 | + M5.Lcd.setCursor(240, 200); |
| 44 | + M5.Lcd.print('C'); |
| 45 | +#endif |
| 46 | + M5.Lcd.setCursor(0, 100); |
| 47 | +} |
| 48 | + |
| 49 | +void loop() { |
| 50 | + |
| 51 | +#ifdef RX |
| 52 | +M5.update(); |
| 53 | + if(Serial2.available()) { |
| 54 | + char ch = Serial2.read(); |
| 55 | + M5.Lcd.print(ch); |
| 56 | + } |
| 57 | + |
| 58 | + if (M5.BtnA.wasReleased()) { |
| 59 | + M5.Lcd.clear(); |
| 60 | + M5.Lcd.setCursor(0, 0); |
| 61 | + } |
| 62 | +#elif defined TX |
| 63 | + Serial2.write('A'); |
| 64 | + delay(50); |
| 65 | +#else |
| 66 | + if (M5.BtnA.wasReleased()) { |
| 67 | + ch = 'A'; |
| 68 | + Serial2.write(ch); |
| 69 | + } else if (M5.BtnB.wasReleased()) { |
| 70 | + ch = 'B'; |
| 71 | + Serial2.write(ch); |
| 72 | + } else if (M5.BtnC.wasReleased()) { |
| 73 | + ch = 'C'; |
| 74 | + Serial2.write(ch); |
| 75 | + } |
| 76 | + M5.update(); |
| 77 | + if(Serial2.available()) { |
| 78 | + char ch = Serial2.read(); |
| 79 | + M5.Lcd.print(ch); |
| 80 | + } |
| 81 | +#endif |
| 82 | + |
| 83 | + |
| 84 | +} |
0 commit comments