Обновление до версии 0.3.0
- обновлен elbear_fw_bootloader - добавлена проверка контрольной суммы каждой строки hex файла. - в модуль работы с АЦП добавлена функция analogReadResolution(). Функция analogRead() теперь возвращает усредненное по 10 измерениям значение. - общая функция обработки прерываний перенесена в память RAM. Обработчики прерываний модулей External Interrupts и Advanced I/O (функция tone()) так же перенесены в память RAM для увеличения скорости выполнения кода. - в пакет добавлены библиотеки EEPROM, Servo, SoftSerial, NeoPixel, MFRC522 адаптированные для работы с платой Elbear Ace-Uno. - добавлено описание особенностей работы с пакетом
This commit was merged in pull request #6.
This commit is contained in:
1 parent
7a7c552743
commit
766b7b32ea
114 files changed
+11064
-666
No files matched your search
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
Software serial multiple serial test
|
||||
|
||||
Receives from the two software serial ports,
|
||||
sends to the hardware serial port.
|
||||
|
||||
In order to listen on a software port, you call port.listen().
|
||||
When using two software serial ports, you have to switch ports
|
||||
by listen()ing on each one in turn. Pick a logical time to switch
|
||||
ports, like the end of an expected transmission, or when the
|
||||
buffer is empty. This example switches ports when there is nothing
|
||||
more to read from a port
|
||||
|
||||
The circuit:
|
||||
Two devices which communicate serially are needed.
|
||||
* First serial device's TX attached to digital pin 2(RX), RX to pin 6(TX)
|
||||
* Second serial device's TX attached to digital pin 8(RX), RX to pin 10(TX)
|
||||
|
||||
Note:
|
||||
Not all pins on the Elbear Ace-Uno support interrupts,
|
||||
so only the following can be used for RX:
|
||||
2, 3, 4, 5, 8, 9
|
||||
*/
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
// software serial #1: RX = digital pin 2, TX = digital pin 6
|
||||
SoftwareSerial portOne(2, 6);
|
||||
// software serial #2: RX = digital pin 8, TX = digital pin 10
|
||||
SoftwareSerial portTwo(8, 10);
|
||||
|
||||
// active port is changed by user button pressing
|
||||
volatile bool isPortOneActive = true;
|
||||
void btn_pressed_callback(void)
|
||||
{
|
||||
// change active port
|
||||
if (isPortOneActive)
|
||||
{
|
||||
portTwo.listen();
|
||||
Serial.println("Port two is listening");
|
||||
isPortOneActive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
portOne.listen();
|
||||
Serial.println("Port one is listening");
|
||||
isPortOneActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Open serial communications and wait for port to open
|
||||
Serial.begin(115200);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// attach interrupt to user button
|
||||
attachInterrupt(digitalPinToInterrupt(BTN_BUILTIN), btn_pressed_callback, FALLING);
|
||||
|
||||
// Start each software serial port
|
||||
portOne.begin(57600);
|
||||
portTwo.begin(57600);
|
||||
|
||||
// First listen to port one
|
||||
portOne.listen();
|
||||
isPortOneActive = true;
|
||||
Serial.println("Port one is listening");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// check data from port one
|
||||
if (portOne.available())
|
||||
{
|
||||
Serial.println("Data from port one:");
|
||||
// while there is data coming in, read it
|
||||
// and send to the hardware serial port
|
||||
while (portOne.available() > 0)
|
||||
Serial.write((char)portOne.read());
|
||||
|
||||
// blank line to separate data from the two ports
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
// check data from port two
|
||||
if (portTwo.available())
|
||||
{
|
||||
Serial.println("Data from port two:");
|
||||
// while there is data coming in, read it
|
||||
// and send to the hardware serial port
|
||||
while (portTwo.available() > 0)
|
||||
Serial.write((char)portTwo.read());
|
||||
|
||||
// blank line to separate data from the two ports
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user