Hi everyone, I am new here to seek help with my code. I am a student from UCD, because of the coronavirus, I was not able to get help from my professor or TA.
I am using the light sensor on the circuit playground to collect data. But I am not sure how do I make a counter for comparing with two sets of data.
I have attached my code file. Please talk a look at my file and give me some hints if you had any suggestions about this. Thank you for your time!
#include <Adafruit_CircuitPlayground.h>
float threshold;
float peak;
float trough;
float pulse;
float temp;
bool dir;
int counter;
float increase;
void setup() {
while (!Serial);
Serial.begin (115200);
Serial.println("Circuitplayground Pulse sensor test");
CircuitPlayground.begin();
CircuitPlayground.setBrightness(255);
CircuitPlayground.setPixelColor(1, 0, 255, 0);
counter=0;
threshold=240;
temp=0;
increase=0;
}
void loop() {
Serial.println(CircuitPlayground.lightSensor());
delay(20);
pulse = CircuitPlayground.lightSensor();
peak=threshold+10;
trough=threshold-10;
if(pulse>threshold){
CircuitPlayground.setPixelColor(5, 0, 0, 255);
} else {
CircuitPlayground.setPixelColor(5, 0, 0, 0);
}
if (pulse > peak){
threshold=threshold+10;
} else if (pulse < trough){
threshold=threshold-10;
}
if (pulse>increase) {
counter=counter+1;
increase = increase+pulse;
}
if (counter==5){
temp=increase;
increase=0;
}
if (counter==10) {
if (temp<increase) {
dir=true;
} else {
dir=false;
}
counter=0;
}
if (dir==true && pulse > peak){
threshold=threshold+10;
} else if (dir==false && pulse < trough ){
threshold=threshold-10;
}
}
des178Final3.ino (1.32 KB)