こんにちは。 ハイパーターミナルで接続したシリアルデバイスで、 'd' を押すとステータスレポートが表示されるものがあります。
Arduinoに接続されたボタンを押し、シリアルデバイスにbを送信し、そこから戻ってくるステータス情報を見たいと思います。
この時点でシリアルデバイスをarduinoに接続し、メッセージを見ることができますが、ピン2に接続したスイッチを押しても、シリアルデバイスは期待通りのステータス出力を送ってくれず、ハイパーターミナルでコンピュータと直接シリアル接続しても、ステータス出力は見られません。
どなたか、この件に関する経験やご意見をお持ちの方はいらっしゃいますか?
#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial portOne(10, 11);
const int buttonPin = 2; // the number of the pushbutton pin
const int button1Pin = 4;
const int ledPin = 13; // the number of the LED pin
//define char to send to serial
char stat = 'd';
char route = '\x14';
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int button1State = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(button1Pin, INPUT);
Serial.begin(4800);
while (!Serial) {; // wait for serial port to connect. Needed for native USB port only
}
// Start each software serial port
portOne.begin(4800);
while (!portOne) {; // wait for serial port to connect. Needed for native USB port only
}
}
// the loop function runs over and over again forever
void loop() {
static int Once = 0;
static int Once1 = 0;
buttonState = digitalRead(buttonPin);
button1State = digitalRead(button1Pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH ) {
if (Once == 0) {
Once = 1;
// turn LED on so I can tell the button is working
digitalWrite(ledPin, HIGH);
// send d to Radio
portOne.write(stat);
// send d to serial monitor so I can see the charector
Serial.print(stat);
}
}
if (buttonState == LOW) {
// turn LED off:
Once = 0;
digitalWrite(ledPin, LOW);
}
// check if the other pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button1State == HIGH) {
if (Once1 == 0) {
Once1 = 1;
// turn LED on:
// digitalWrite(ledPin, HIGH);
// send ctrl-t to radio
portOne.write(route);
}
}
if (button1State == LOW) {
// turn LED off:
//digitalWrite(ledPin, LOW);
Once1 = 0;
}
portOne.listen();
// read data from the Software Serial portOne
// and send to the hardware serial port:
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.print(inByte);
}
}