optimized

This commit is contained in:
matt
2020-05-15 05:30:37 -07:00
parent 1b11b44336
commit 0adeb9a7b1
15 changed files with 983 additions and 342 deletions

View File

@@ -0,0 +1,40 @@
#include <AltSoftSerial.h>
// AltSoftSerial always uses these pins:
//
// Board Transmit Receive PWM Unusable
// ----- -------- ------- ------------
// Teensy 3.0 & 3.1 21 20 22
// Teensy 2.0 9 10 (none)
// Teensy++ 2.0 25 4 26, 27
// Arduino Uno 9 8 10
// Arduino Leonardo 5 13 (none)
// Arduino Mega 46 48 44, 45
// Wiring-S 5 6 4
// Sanguino 13 14 12
// This example code is in the public domain.
AltSoftSerial altSerial;
void setup() {
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor to open
Serial.println("AltSoftSerial Test Begin");
altSerial.begin(9600);
altSerial.println("Hello World");
}
void loop() {
char c;
if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}

View File

@@ -0,0 +1,52 @@
// AltSoftSerial Receive Test
//
// Transmit data with Serial1 and try to receive
// it with AltSoftSerial. You must connect a wire
// from Serial1 TX to AltSoftSerial RX.
#include <AltSoftSerial.h>
AltSoftSerial altser;
const int mybaud = 9600;
// Board Serial1 TX AltSoftSerial RX
// ----- ---------- ----------------
// Teensy 3.x 1 20
// Teensy 2.0 8 (D3) 10 (C7)
// Teensy++ 2.0 3 (D3) 4 (D4)
// Arduino Leonardo 1 13
// Arduino Mega 18 48
// Serial1 on AVR @ 16 MHz minimum baud is 245
// Serial1 on Teensy 3.2 @ 96 MHz minimum baud is 733
// This example code is in the public domain.
byte sentbyte;
unsigned long prevmillis;
byte testbyte=0xF0;
void setup() {
delay(200);
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
Serial1.begin(mybaud); // connect a wire from TX1
altser.begin(mybaud); // to AltSoftSerial RX
Serial.println("AltSoftSerial Receive Test");
prevmillis = millis();
}
void loop() {
// transmit a test byte on Serial 1
if (millis() - prevmillis > 250) {
sentbyte = testbyte++;
Serial1.write(sentbyte);
prevmillis = millis();
}
// attempt to receive it by AltSoftSerial
if (altser.available() > 0) {
byte b = altser.read();
Serial.println(b);
if (b != sentbyte) Serial.println("***** ERROR *****");
}
}

View File

@@ -0,0 +1,97 @@
#include <AltSoftSerial.h>
// AltSoftSerial show configuration example
// Will print library configuration to default serial port
// Open your serial monitor to see config for your board
// Printout would repeat every 10sec (just in case you missed it somehow)
// Print Configuration
// -----------------------
// Direct include AltSoftSerial internals to obtaion PIN setup (you do not need this in regular code)
// This example code is in the public domain.
#include <config/AltSoftSerial_Boards.h>
void printAltSoftSerialSetup(Stream &port)
{
#define PRINT_PFX "AltSoftSerial:"
#define PRINT_PIN_NAME(pin,name) { char buffer[128+1]; sprintf(buffer, PRINT_PFX "PIN:%2d %s", (int)pin, (const char*)name); port.println(buffer); }
port.println(PRINT_PFX "Setup info: begin");
#if defined(ALTSS_USE_FTM0)
port.println(PRINT_PFX "USE FTM0");
#endif
#if defined(ALTSS_USE_TIMER1)
port.println(PRINT_PFX "USE TIMER1");
#endif
#if defined(ALTSS_USE_TIMER2)
port.println(PRINT_PFX "USE TIMER2");
#endif
#if defined(ALTSS_USE_TIMER3)
port.println(PRINT_PFX "USE TIMER3");
#endif
#if defined(ALTSS_USE_TIMER4)
port.println(PRINT_PFX "USE TIMER4");
#endif
#if defined(ALTSS_USE_TIMER5)
port.println(PRINT_PFX "USE TIMER5");
#endif
#if defined(INPUT_CAPTURE_PIN)
PRINT_PIN_NAME(INPUT_CAPTURE_PIN,"RX");
#endif
#if defined(OUTPUT_COMPARE_A_PIN)
PRINT_PIN_NAME(OUTPUT_COMPARE_A_PIN,"TX");
#endif
#if defined(OUTPUT_COMPARE_B_PIN)
PRINT_PIN_NAME(OUTPUT_COMPARE_B_PIN,"(unused PWM)");
#endif
#if defined(OUTPUT_COMPARE_C_PIN)
PRINT_PIN_NAME(OUTPUT_COMPARE_C_PIN,"(unused PWM)");
#endif
#if defined(OUTPUT_COMPARE_D_PIN)
PRINT_PIN_NAME(OUTPUT_COMPARE_D_PIN,"(unused PWM)");
#endif
#if defined(OUTPUT_COMPARE_E_PIN)
PRINT_PIN_NAME(OUTPUT_COMPARE_E_PIN,"(unused PWM)");
#endif
#if defined(OUTPUT_COMPARE_F_PIN)
PRINT_PIN_NAME(OUTPUT_COMPARE_F_PIN,"(unused PWM)");
#endif
port.println(PRINT_PFX "Setup info: end");
#undef PRINT_PIN_NAME
#undef PRINT_PFX
}
void setup()
{
// Open default serial to dump config to
Serial.begin(9600);
while (!Serial) ; // wait for serial monitor
printAltSoftSerialSetup(Serial);
}
void loop()
{
// Repeat every 10 sec (just in case)
delay(10000);
Serial.println("");
printAltSoftSerialSetup(Serial);
}