i want to make an arduino program with Local Minimum and Local Maximum. I have waves and i want to define a parameter for the maximal and the minimal value in each wave. The rest i can prog, but how i get the parameters with a state machine? Did anyone have an example code to adjust?
Thanks for your reply. I get an IR value in waves form so i don't set the waves, i read it via input on the arduino. I will post the example code in the next minuts.
/*
MAX30105 Breakout: Output all the raw Red/IR/Green readings
By: Nathan Seidle @ SparkFun Electronics
Date: October 2nd, 2016
https://github.com/sparkfun/MAX30105_Breakout
Outputs all Red/IR/Green values.
Hardware Connections (Breakoutboard to Arduino):
-5V = 5V (3.3V is allowed)
-GND = GND
-SDA = A4 (or SDA)
-SCL = A5 (or SCL)
-INT = Not connected
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
but it will also run at 3.3V.
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
*/
#include <Wire.h>
#include "MAX30105.h"
MAX30105 particleSensor;
#define debug Serial //Uncomment this line if you're using an Uno or ESP
//#define debug SerialUSB //Uncomment this line if you're using a SAMD21
void setup()
{
debug.begin(9600);
debug.println("MAX30105 Basic Readings Example");
// Initialize sensor
if (particleSensor.begin() == false)
{
debug.println("MAX30105 was not found. Please check wiring/power. ");
while (1);
}
particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
}
void loop()
{
debug.print(" R[");
debug.print(particleSensor.getRed());
debug.print("] IR[");
debug.print(particleSensor.getIR());
debug.print("] G[");
debug.print(particleSensor.getGreen());
debug.print("]");
debug.println();
}
#define MyHW
#ifdef MyHW
# include "sim.hh"
struct MAX30105 {
int red;
int redDir;
MAX30105 (void) { redDir = 1; }
bool begin (void) { return true; }
int setup (void) { return 0; }
int getRed (void) {
red += redDir;
if (10 <= red || -5 >= red)
redDir = -redDir;
return red;
}
int getIR (void) { return 0; }
int getGreen (void) { return 0; }
};
#else
# include <Wire.h>
# include "MAX30105.h"
#endif
MAX30105 particleSensor;
#define debug Serial //Uncomment this line if you're using an Uno or ESP
//#define debug SerialUSB //Uncomment this line if you're using a SAMD21
char s [80];
int redMax;
int redMin;
// -----------------------------------------------------------------------------
void loop()
{
int red = particleSensor.getRed();
int ir = particleSensor.getIR();
int grn = particleSensor.getGreen();
if (redMax < red)
redMax = red;
if (redMin > red)
redMin = red;
sprintf (s, " %6d %6d %6d", red, redMax, redMin);
debug.print (s);
sprintf (s, ", %6d, %6d", ir, grn);
debug.println (s);
}
// -----------------------------------------------------------------------------
void setup()
{
debug.begin(9600);
debug.println("MAX30105 Basic Readings Example");
// Initialize sensor
if (particleSensor.begin() == false)
{
debug.println("MAX30105 was not found. Please check wiring/power. ");
while (1);
}
particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
redMax = redMin = particleSensor.getRed();
}
I have done some changes and try it with an other sensor, but im prety sure that the values are not correct, maybe you can have a look on it?
#define MyHW
#ifdef MyHW
# include <Wire.h>
#include <DFRobot_MAX30102.h>
#endif
DFRobot_MAX30102 particleSensor;
#define debug Serial //Uncomment this line if you're using an Uno or ESP
//#define debug SerialUSB //Uncomment this line if you're using a SAMD21
char s [80];
I get in the serial monitor values like this: