удалила лишнее, протестировала
This commit is contained in:
1 parent
d9946ff386
commit
3b26203ebb
10 files changed
+87
-277
No files matched your search
@@ -34,7 +34,6 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#define IR_RECEIVE_PIN 2
|
||||
//#define IR_RECEIVE_PIN 3
|
||||
|
||||
/*
|
||||
* Helper macro for getting a macro definition as string
|
||||
@@ -42,36 +41,17 @@
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
|
||||
#if !(defined(EICRA) && defined(EIFR) && defined(EIMSK))
|
||||
void measureTimingISR(void);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(115200);
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
; // Wait for Serial to become available. Is optimized away for some cores.
|
||||
|
||||
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \
|
||||
|| defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217)
|
||||
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
|
||||
#endif
|
||||
// Just to know which program is running on my Arduino
|
||||
Serial.println(F("START " __FILE__ " from " __DATE__));
|
||||
|
||||
#if defined(EICRA) && defined(EIFR) && defined(EIMSK)
|
||||
# if (IR_RECEIVE_PIN == 2)
|
||||
EICRA |= _BV(ISC00); // interrupt on any logical change
|
||||
EIFR |= _BV(INTF0); // clear interrupt bit
|
||||
EIMSK |= _BV(INT0); // enable interrupt on next change
|
||||
# elif (IR_RECEIVE_PIN == 3)
|
||||
EICRA |= _BV(ISC10); // enable interrupt on pin3 on both edges for ATmega328
|
||||
EIFR |= _BV(INTF1); // clear interrupt bit
|
||||
EIMSK |= _BV(INT1); // enable interrupt on next change
|
||||
# endif
|
||||
#else
|
||||
attachInterrupt(digitalPinToInterrupt(IR_RECEIVE_PIN), measureTimingISR, CHANGE);
|
||||
#endif
|
||||
Serial.println(F("Ready to analyze NEC IR signal at pin " STR(IR_RECEIVE_PIN)));
|
||||
Serial.println();
|
||||
}
|
||||
@@ -149,13 +129,9 @@ void loop() {
|
||||
/*
|
||||
* This check enables statistics for longer protocols like Kaseikyo/Panasonics
|
||||
*/
|
||||
#if !defined(ARDUINO_ARCH_MBED)
|
||||
noInterrupts();
|
||||
#endif
|
||||
uint32_t tLastMicros = LastMicros;
|
||||
#if !defined(ARDUINO_ARCH_MBED)
|
||||
interrupts();
|
||||
#endif
|
||||
uint32_t tMicrosDelta = micros() - tLastMicros;
|
||||
|
||||
if (tMicrosDelta > 10000) {
|
||||
@@ -189,19 +165,7 @@ void loop() {
|
||||
* The interrupt handler.
|
||||
* Just add to the appropriate timing structure.
|
||||
*/
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
void IRAM_ATTR measureTimingISR()
|
||||
#else
|
||||
# if defined(EICRA) && defined(EIFR) && defined(EIMSK)
|
||||
# if (IR_RECEIVE_PIN == 2)
|
||||
ISR(INT0_vect)
|
||||
# elif (IR_RECEIVE_PIN == 3)
|
||||
ISR(INT1_vect)
|
||||
# endif
|
||||
# else
|
||||
void measureTimingISR()
|
||||
# endif
|
||||
#endif
|
||||
{
|
||||
uint32_t tMicros = micros();
|
||||
uint32_t tMicrosDelta = tMicros - LastMicros;
|
||||
|
||||
Reference in new issue
Block a user