所以我试图用 arduino 控制代币接收器。 我正在尝试通过键盘发送 AT 命令! 例如,如果我在键盘上按“D”,我想发送一个像“AT%A”这样的 AT 命令来将硬币传送到钱箱
这是我的代码,第一部分没问题,当我插入硬币时,我在串行监视器上得到了结果,但我现在卡在相反的状态,发送命令来控制硬币接收器 escrw
#include <SoftwareSerial.h>
#include <Keypad.h>
SoftwareSerial mySerial(10, 11); // RX, TX
String readString = ""; // a String to hold incoming data
String x="AT%A";
bool stringComplete = false;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys [ROWS] [COLS] = { {'1', '4', '7', '*'},
{'2', '5', '8', '0'},
{'3', '6', '9', '#'},
{'A', 'B', 'C', 'D'} };
byte rowPins [COLS] = {27,29,31,33}; //Columns 0 to 3
byte colPins[ROWS] = {35,37,25,23}; //Rows 0 to 3
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); // whether the string is complete
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Veillez inserez les piéces");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
/*void loop() { // run over and over
if (mySerial.available()) {
const int str = Serial.write(mySerial.read());
Serial.print(str);
}
*/
void loop() {
char customKey = customKeypad.getKey();
while (mySerial.available()) {
delay(3);
char c = mySerial.read();
readString += c;
}
readString.trim();
if (readString.length() >0) {
if (readString == "+C:00002"){
Serial.println("1000 millimes inserées");
}
else if (readString == "+C:00003"){
Serial.println("100 millimes inserées");
}
else if (readString == "+C:00020"){
Serial.println("200 millimes inserées");
}
else if (readString == "+C:00017"){
Serial.println("2000 millimes inserées");
}
else if (readString == "+C:00011"){
Serial.println("500 millimes inserées");
}
else if (readString == "+C:00008"){
Serial.println("50 millimes inserées");
}
else Serial.println(readString);
readString="";
}
while (Serial.available()) {
mySerial.write(Serial.read());
if (customKey=='D'){
mySerial.write("AT%A");
Serial.println("opening");
}
}}
```````````````````````````````````````````````````````````````````````````````````````````````````