Dear all,
I am using the following code for AS3935 lightning sensor. The system works very well.
However, I would like to know if would be possible reconstruct the code avoiding the lines 21 and 81.
Both lines contain: void AS3935_ISR();
In another words, I would like to have only two voids, void setup(); and void loop();
Is this possible or not. If it is possible How can I just the original code?
Thanks for any help...
Cesar
#include <I2C.h>
#include <PWFusion_AS3935_I2C.h>
// interrupt trigger global var
volatile int8_t AS3935_ISR_Trig = 0;
// defines for hardware config
#define SI_PIN 19
#define IRQ_PIN 18
#define AS3935_ADD 0x03 // x03 - standard PWF SEN-39001-R01 config
#define AS3935_CAPACITANCE 64 // <-- SET THIS VALUE TO THE NUMBER LISTED ON YOUR BOARD
// defines for general chip settings
#define AS3935_INDOORS 1
#define AS3935_OUTDOORS 0
#define AS3935_DIST_DIS 0
#define AS3935_DIST_EN 1
// prototypes
void AS3935_ISR();
PWF_AS3935_I2C lightning0((uint8_t)IRQ_PIN, (uint8_t)SI_PIN, (uint8_t)AS3935_ADD);
void setup()
{
Serial.begin(9600);
Serial.println("Playing With Fusion: AS3935 Lightning Sensor, SEN-39001-R01");
Serial.println("beginning boot procedure....");
// setup for the the I2C library: (enable pullups, set speed to 400kHz)
I2c.begin();
I2c.pullup(true);
I2c.setSpeed(1);
delay(2);
lightning0.AS3935_DefInit(); // set registers to default
// now update sensor cal for your application and power up chip
lightning0.AS3935_ManualCal(AS3935_CAPACITANCE, AS3935_OUTDOORS, AS3935_DIST_EN);
// enable interrupt (hook IRQ pin to Arduino Uno/Mega interrupt input: 0 -> pin 2, 1 -> pin 3 )
attachInterrupt(0, AS3935_ISR, RISING); //Modo original
//attachInterrupt(digitalPinToInterrupt(IRQ_PIN), AS3935_ISR, RISING); //Modo sugerido
lightning0.AS3935_PrintAllRegs();
AS3935_ISR_Trig = 0; // clear trigger
}
void loop()
{
// This program only handles an AS3935 lightning sensor. It does nothing until
// an interrupt is detected on the IRQ pin.
while(0 == AS3935_ISR_Trig){}
delay(5);
// reset interrupt flag
AS3935_ISR_Trig = 0;
// now get interrupt source
uint8_t int_src = lightning0.AS3935_GetInterruptSrc();
if(0 == int_src)
{
Serial.println("interrupt source result not expected");
}
else if(1 == int_src)
{
uint8_t lightning_dist_km = lightning0.AS3935_GetLightningDistKm();
Serial.print("Lightning detected! Distance to strike: ");
Serial.print(lightning_dist_km);
Serial.println(" kilometers");
}
else if(2 == int_src)
{
Serial.println("Disturber detected");
}
else if(3 == int_src)
{
Serial.println("Noise level too high");
}
lightning0.AS3935_PrintAllRegs(); // for debug...
}
// this is irq handler for AS3935 interrupts, has to return void and take no arguments
// always make code in interrupt handlers fast and short
void AS3935_ISR()
{
AS3935_ISR_Trig = 1;
}