Skip to content

Commit 17ac8d6

Browse files
authored
Add files via upload
1 parent 2eaa35b commit 17ac8d6

File tree

2 files changed

+50
-59
lines changed

2 files changed

+50
-59
lines changed

examples/Transceiver/Transceiver.ino

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,28 @@
44
55
J1850-Arduino-Transceiver-Library
66
*/
7+
#define EI_ARDUINO_INTERRUPTED_PIN
8+
#include <EnableInterrupt.h>
79
#include <PwmTransceiver.h>
810

9-
volatile bool PwmTransceiver::flagDecoder;
10-
volatile unsigned long PwmTransceiver::timeOld;
1111
const int rx_pin = 3; // https://goo.gl/nHC95v
1212
const int tx_pin = 13;
1313

1414
PwmTransceiver Transceiver(rx_pin, tx_pin);
1515

16-
void setup()
17-
{
16+
void setup() {
1817
Serial.begin(2000000);
1918
Serial.println("PwmTransceiver");
2019
Transceiver.begin(1200);
2120
}
2221

23-
void loop()
24-
{
25-
while (1)
26-
{
27-
while (Transceiver.isReceiving())
28-
{
29-
Transceiver.receive();
30-
}
31-
if (Transceiver.available())
32-
{
33-
Serial.print(Transceiver.readString());
34-
}
35-
if (Serial.available())
36-
{
37-
Transceiver.print(Serial.readString());
38-
}
39-
// Put non-blocking code here
22+
void loop() {
23+
while (Transceiver.isReceiving());
24+
if (Transceiver.available()) {
25+
Serial.print(Transceiver.readString());
4026
}
27+
if (Serial.available()) {
28+
Transceiver.print(Serial.readString());
29+
}
30+
// Put non-blocking code here
4131
}
Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
/*
2-
Created by: Esposito Vittorio
3-
GitHub: https://github.com/VittorioEsposito
4-
5-
J1850-Arduino-Transceiver-Library
6-
*/
7-
#include <PwmTransceiver.h>
8-
9-
volatile bool PwmTransceiver::flagDecoder;
10-
volatile unsigned long PwmTransceiver::timeOld;
11-
const int rx_pin = 3; // https://goo.gl/nHC95v
12-
const int tx_pin = 13;
13-
const int en_pin = 11; // To power up/down the module
14-
15-
PwmTransceiver Transceiver(rx_pin, tx_pin);
16-
17-
String str;
18-
19-
void setup() {
20-
Serial.begin(9600);
21-
Transceiver.begin(1200); // 1200 bit per second
22-
Transceiver.setEnablePin(en_pin); // Set power up/down pin
23-
Transceiver.powerDown(); // Power down module
24-
}
25-
26-
void loop() {
27-
28-
// Alternative way: send a string
29-
if (Serial.available() > 0) {
30-
Transceiver.powerUp(); // Power up module
31-
delay(1000); // Radio-module is powering up
32-
str = Serial.readString(); // One second timeOut
33-
Transceiver.print(str);
34-
Serial.println(str);
35-
delay(1000);
36-
Transceiver.powerDown(); // Power down module
37-
}
38-
1+
/*
2+
Created by: Esposito Vittorio
3+
GitHub: https://github.com/VittorioEsposito
4+
5+
J1850-Arduino-Transceiver-Library
6+
*/
7+
#define EI_ARDUINO_INTERRUPTED_PIN
8+
#include <EnableInterrupt.h>
9+
#include <PwmTransceiver.h>
10+
11+
const int rx_pin = 3; // https://goo.gl/nHC95v
12+
const int tx_pin = 13;
13+
const int en_pin = 11; // To power up/down the module
14+
15+
PwmTransceiver Transceiver(rx_pin, tx_pin);
16+
17+
String str;
18+
19+
void setup() {
20+
Serial.begin(2000000);
21+
Serial.println("PwmTransceiver");
22+
Transceiver.begin(1200); // 1200 bit per second
23+
Transceiver.setEnablePin(en_pin); // Set power up/down pin
24+
Transceiver.powerDown(); // Power down module
25+
}
26+
27+
void loop() {
28+
29+
// Send a string
30+
if (Serial.available() > 0) {
31+
Transceiver.powerUp(); // Power up module
32+
delay(1000); // Radio-module is powering up
33+
str = Serial.readString(); // One second timeOut
34+
Transceiver.print(str);
35+
Serial.println(str);
36+
delay(1000);
37+
Transceiver.powerDown(); // Power down module
38+
}
39+
3940
}

0 commit comments

Comments
 (0)