I tried to debug again with my project. When debug started, i paused the debug as you said. Then the cursor returned here.
Here is my code.
#include <Arduino.h>
#define RXD2 16
#define TXD2 17
#define DE 18
static const int C1 = 26, C2 = 25, C3 = 23, C4 = 22, C5 = 21, C6 = 19, R1 = 27, R2 = 32, R3 = 33;
unsigned long previousMillis = 0;
const long interval = 1000;
uint8_t button, prev_button;
uint8_t read_button() {
digitalWrite(C1, 1);
digitalWrite(C2, 0);
digitalWrite(C3, 0);
digitalWrite(C4, 0);
digitalWrite(C5, 0);
digitalWrite(C6, 0);
delay(3);
if (digitalRead(R1)) return (1);
else if (digitalRead(R2)) return (7);
else if (digitalRead(R3)) return (13);
digitalWrite(C1, 0);
digitalWrite(C2, 1);
digitalWrite(C3, 0);
digitalWrite(C4, 0);
digitalWrite(C5, 0);
digitalWrite(C6, 0);
delay(3);
if (digitalRead(R1)) return (2);
else if (digitalRead(R2)) return (8);
else if (digitalRead(R3)) return (14);
digitalWrite(C1, 0);
digitalWrite(C2, 0);
digitalWrite(C3, 1);
digitalWrite(C4, 0);
digitalWrite(C5, 0);
digitalWrite(C6, 0);
delay(3);
if (digitalRead(R1)) return (3);
else if (digitalRead(R2)) return (9);
else if (digitalRead(R3)) return (15);
digitalWrite(C1, 0);
digitalWrite(C2, 0);
digitalWrite(C3, 0);
digitalWrite(C4, 1);
digitalWrite(C5, 0);
digitalWrite(C6, 0);
delay(3);
if (digitalRead(R1)) return (4);
else if (digitalRead(R2)) return (10);
else if (digitalRead(R3)) return (16);
digitalWrite(C1, 0);
digitalWrite(C2, 0);
digitalWrite(C3, 0);
digitalWrite(C4, 0);
digitalWrite(C5, 1);
digitalWrite(C6, 0);
delay(3);
if (digitalRead(R1)) return (5);
else if (digitalRead(R2)) return (11);
else if (digitalRead(R3)) return (17);
digitalWrite(C1, 0);
digitalWrite(C2, 0);
digitalWrite(C3, 0);
digitalWrite(C4, 0);
digitalWrite(C5, 0);
digitalWrite(C6, 1);
delay(3);
if (digitalRead(R1)) return (6);
else if (digitalRead(R2)) return (12);
else if (digitalRead(R3)) return (18);
return 0;
}
void buttontask() {
for (;;) {
button = 0;
button = read_button();
if (button != prev_button) {
Serial.println(button);
}
prev_button = button;
delay(100);
}
}
void uart_send(int data_send) {
digitalWrite(DE, 1);
Serial2.println(data_send);
Serial2.flush();
digitalWrite(DE, 0);
}
void setup() {
Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
Serial.begin(115200);
pinMode(C1, OUTPUT);
pinMode(C2, OUTPUT);
pinMode(C3, OUTPUT);
pinMode(C4, OUTPUT);
pinMode(C5, OUTPUT);
pinMode(C6, OUTPUT);
pinMode(R1, INPUT_PULLDOWN);
pinMode(R2, INPUT_PULLDOWN);
pinMode(R3, INPUT_PULLDOWN);
pinMode(DE, OUTPUT);
}
void loop() {
buttontask();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Serial.println("Gonderdim:");
Serial.println(button);
uart_send(button);
}
}