When I adjust my preprocessor commands (e.g. SQUELCH was defined as 1 then I changed it to 0) I get a bunch of errors such as:
ATCMUS.cpp: In function 'void setup()':
ATCMUS:19: error: 'orangeLED' was not declared in this scope
ATCMUS:32: error: 'LEDoff' was not declared in this scope
ATCMUS:37: error: 'LEDoff' was not declared in this scope
ATCMUS.cpp: In function 'void loop()':
ATCMUS:49: error: 'greenLED' was not declared in this scope
ATCMUS:67: error: 'redLED' was not declared in this scope
when they were just fine before. Why is it suddenly not seeing these functions. I had the same errors with digitalWrite() and other basic arduino constructs (HIGH, LOW, INPUT, etc) until I included Arduino.h. I've never had to seperately declare my functions (void orangeLED(); ) before and the preprocessors make it much easier for me to change the program based on my requirements.
Code below:
#include <Arduino.h>
#define DEBUG 1
#define SQUELCH 0
#if SQUELCH
int potPin = A0; // select the input pin for the potentiometer
#endif
int sensorPin = A5;
int rled = 6;
int gled = 8;
int relay = 2;
int overridepin = 9;
void setup()
{
pinMode(rled, OUTPUT);
pinMode(gled, OUTPUT);
orangeLED(); //indicate setup
pinMode(relay, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(overridepin, INPUT_PULLUP);
#if SQUELCH
pinMode(potPin,INPUT);
#endif
#if DEBUG
Serial.begin(9600);
#endif
for (int i=0;i<4;i++)//warn setup finishing
{
LEDoff();
delay(250);
orangeLED();
delay(250);
}
LEDoff();
}
void loop()
{
float sensitivity = 0.00;
int sensorValue = 0;
int sensValold = 0;
float diff = 0.00;
if (digitalRead(overridepin)==LOW)
{
greenLED();
digitalWrite(relay, LOW);
#if DEBUG
Serial.println("Override Engaged");
#endif
delay(2000);
}
else
{
#if SQUELCH
[redacted]
#else
[redacted]
#endif
redLED();
sensorValue = analogRead(sensorPin);
diff = (float)(sensorValue - sensValold)/(float)(sensorValue);
#if DEBUG
Serial.println(abs(diff));
#if SQUELCH
Serial.print("Sensitivity: ");
Serial.println(sensitivity);
#endif
#endif
if (abs(diff) > sensitivity)
{
digitalWrite(relay, LOW);
delay(2000);
}
else
{
digitalWrite(relay, HIGH);
}
sensValold = sensorValue;
delay(75);
}
}
void redLED()
{
digitalWrite(rled,HIGH);
digitalWrite(gled,LOW);
}
void greenLED()
{
digitalWrite(gled,HIGH);
digitalWrite(rled,LOW);
}
void orangeLED()
{
digitalWrite(rled,HIGH);
digitalWrite(gled,HIGH);
}
void LEDoff()
{
digitalWrite(rled,LOW);
digitalWrite(gled,LOW);
}