Hello! I'm fairly new to Arduino and I'm attempting to Prompt a user to input a threshold percentage (threshold %) in the Serial Monitor. When a pushbutton is pressed down, the GSR sensor will calculate the baseline SCL (skin conductance level). When the pushbutton returns to its original position, the program turns the LED on the following Boolean statement is true:
SCLmeasured > SCLbaseline + (SCLbaseline * Threshold %)
My code is below. It is throwing me a very strange error and I'm not sure what to make of it.
I'm not sure of the rules when posting, but I'm sort of at a dead end. Many thanks!
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp: In member function 'availableForWrite':
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:203:1: internal compiler error: Segmentation fault
}
lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status
compilation terminated.
c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
#include "math.h" // include the Math Library
const int VoutPin = 0; //analog input pin A0
const int ButtonPin = 2;
const int LedPin = 8;
int ButtonState = 0;
int index = 0;
float sum = 0;
float Baseline = 0;
float BSCL[60] = {0};
char Junk = ' ';
float Threshold;
float getVoltage(int pin) { //Creates the getVoltage Function
return (analogRead(pin) * 0.004882814);
//This equation converts the 0 to 1023 value that analog Read()
//returns, into a 0.0 to 5.0 value that is the true voltage
}
float voltage = getVoltage(VoutPin);
float Skincond = 1 / ((1500000 / voltage) - 300000);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(LedPin, OUTPUT);
pinMode(ButtonPin, INPUT);
Serial.println("Lets Test Conductance!");
Serial.println("");
Serial.flush();
//-------------------------------------------------------------------------------------------------------------------------------
// Threshold
Serial.println("Enter a value for threshold between 0 and 100%, Press ENTER");
while (Serial.available() == 0) ; // Wait here until input buffer has a character
{
//Setting the Threshold Parameter
if ((Serial.parseFloat() >= 0) && (Serial.parseFloat() <= 100)) {
Threshold = Serial.parseFloat(); // new command in 1.0 forward
Serial.println("Input Percentage is valid, beginning measurement");
Serial.print("Threshold = "); Serial.println(Threshold, DEC);
}
else {
Threshold = Serial.parseFloat(); // new command in 1.0 forward
Serial.println("The Value Entered Is Not A valid percentage.");
Serial.println("Defaulting To Baseline Value of 0");
Serial.print("Threshold = "); Serial.println(Threshold, DEC);
}
while (Serial.available() > 0) // .parseFloat() can leave non-numeric characters
{
Junk = Serial.read() ; // clear the keyboard buffer
}
}
ButtonState = digitalRead(ButtonPin); //Read input from digital pin 2
while (ButtonState == LOW) {
Serial.println("Please Hold The Button for at least 65 seconds To Take a Baseline Skin Conductance Level.");
delay(5000);
ButtonState = digitalRead(ButtonPin); //Read input from digital pin 2
}
}
void loop() {
float voltage;
float time = millis();
ButtonState = digitalRead(ButtonPin); //Read input from digital pin 2
if (ButtonState == HIGH) { //If Button is pushed BaseLine SCL will be calculated
for (index = 0; index < 60; index++) {
voltage = getVoltage(VoutPin);
float Skincond = 1 / ((1500000 / voltage) - 300000);
BSCL[index] = Skincond;
float sum = sum + BSCL[index];
Baseline = sum / 60;
delay(1000);
}
}
else {
if (Skincond > (Baseline + Baseline * (Threshold / 100))) {
digitalWrite(LedPin, HIGH);
}
else (Skincond < (Baseline + Baseline * Threshold)); {
digitalWrite(LedPin, LOW);
}
}
}