|
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 | + |
39 | 40 | }
|
0 commit comments