Since I updated to the new version 6.1.12 I get the error message
"function-xxx was not declared in this scope" for all my external functions.
The code below was working in 6.1.7.
What can I do to resolve this problem?
// constants those won't change. They're used here to set pin numbers:
const int PIRPin = 6; // the number of the pessence sensor pin
const int buttonPin = 7; // the number of the pushbutton pin
const int LDRPin = A0; // select the analog input pin for ldr
const int ledPin1 = 13; // the number of the Blue LED pin
const int ledPin2 = 12; // the number of the Green LED pin
const int ledPin3 = 11; // the number of the Red LED pin
const int ledPin4 = 10; // the number of the X LED pin*/
//Variables will change
boolean ledVal1 = false; // state of LED 1
boolean ledVal2 = false; // state of LED 2
boolean ledVal3 = false; // state of LED 3
boolean ledVal4 = false; // state of LED 4
boolean OverRule = false; // has automation been overruled by user?
unsigned long previousMillis = 0; // will store last time LED was updated
int LDRValue = digitalRead(LDRPin); // will store LDR value (analog)
int b;
//=================================================
void setup()
{
// Set input pins
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH );
pinMode(PIRPin, INPUT);
// Set output pins
pinMode(ledPin1, OUTPUT);
digitalWrite(ledPin1, ledVal1);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin2, ledVal2);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin3, ledVal3);
pinMode(ledPin4, OUTPUT);
digitalWrite(ledPin4, ledVal4);
Serial.begin(9600); //sets serial port for communication
}
void loop()
{
unsigned long currentMillis = millis();
// Get button event and act accordingly
b = checkButton();
if (b == 1) {
OverRule = !OverRule;
//Serial.println(OverRule);
clickEvent();
previousMillis = currentMillis; // reset the counter during absence
}
if (b == 2) {
OverRule = !OverRule;
//Serial.println(OverRule);
doubleClickEvent();
previousMillis = currentMillis; // reset the counter during absence
}
if (b == 3) {
OverRule = !OverRule;
//Serial.println(OverRule);
holdEvent();
previousMillis = currentMillis; // reset the counter during absence
}
//if (b == 4) {OverRule != OverRule; longHoldEvent();} //event 3 is always triggerd along when triggering event 4
//home automation depending on light level and pressence of people
Serial.println(LDRValue);
if (OverRule == false) {
if (digitalRead(PIRPin) == HIGH) {
previousMillis = currentMillis; // reset the counter during absence
if (LDRValue < 750) { //setting a threshold value
// turn LED on:
digitalWrite(ledPin1, HIGH);
} else if (LDRValue > 850) {
// turn LED off:
digitalWrite(ledPin1, LOW);
}
} else {
//Serial.println(currentMillis - previousMillis);
if (currentMillis - previousMillis > 10000) { //if there is no one in the room for a certain time
digitalWrite(ledPin1, LOW); // the light turns off
previousMillis = currentMillis; // reset the counter
}
}
}
//LDRValue = getLight(10,60000); // read the value from the sensor
LDRValue = digitalRead(LDRPin);
if (OverRule == true && digitalRead(PIRPin) == HIGH) {
previousMillis = currentMillis; // reset the counter during absence
} else if (OverRule == true && digitalRead(PIRPin) == LOW) {
//Serial.println(currentMillis - previousMillis);
if (currentMillis - previousMillis > 10000) { //if there is no one in the room for a certain time
digitalWrite(ledPin1, LOW); // the light turns off
OverRule = false;
previousMillis = currentMillis; // reset the counter
}
}
}
//=================================================
// Events to trigger by click and press+hold
void clickEvent() {
ledVal1 = digitalRead(ledPin1);
ledVal1 = !ledVal1;
digitalWrite(ledPin1, ledVal1);
}
void doubleClickEvent() {
ledVal2 = !ledVal2;
digitalWrite(ledPin2, ledVal2);
}
void holdEvent() {
ledVal3 = !ledVal3;
digitalWrite(ledPin3, ledVal3);
}
void longHoldEvent() {
ledVal4 = !ledVal4;
digitalWrite(ledPin4, ledVal4);
}
/*
MULTI-CLICK: One Button, Multiple Events
Oct 12, 2009
Run checkButton() to retrieve a button event:
Click
Double-Click
Hold
Long Hold
*/
// Button timing variables
int debounce = 20; // ms debounce period to prevent flickering when pressing or releasing the button
int DCgap = 250; // max ms between clicks for a double click event
int holdTime = 2000; // ms hold period: how long to wait for press+hold event
int longHoldTime = 5000; // ms long hold period: how long to wait for press+hold event
// Other button variables
boolean buttonVal = LOW; // value read from button
boolean buttonLast = LOW; // buffered value of the button's previous state
boolean DCwaiting = false; // whether we're waiting for a double click (down)
boolean DConUp = false; // whether to register a double click on next release, or whether to wait and click
boolean singleOK = true; // whether it's OK to do a single click
long downTime = -1; // time the button was pressed down
long upTime = -1; // time the button was released
boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered
boolean waitForUp = false; // when held, whether to wait for the up event
boolean holdEventPast = false; // whether or not the hold event happened already
boolean longHoldEventPast = false;// whether or not the long hold event happened already
int checkButton() {
int event = 0;
// Read the state of the button
buttonVal = digitalRead(buttonPin);
// Button pressed down
if (buttonVal == HIGH && buttonLast == LOW && (millis() - upTime) > debounce) {
downTime = millis();
ignoreUp = false;
waitForUp = false;
singleOK = true;
holdEventPast = false;
longHoldEventPast = false;
if ((millis() - upTime) < DCgap && DConUp == false && DCwaiting == true) DConUp = true;
else DConUp = false;
DCwaiting = false;
}
// Button released
else if (buttonVal == LOW && buttonLast == HIGH && (millis() - downTime) > debounce) {
if (not ignoreUp) {
upTime = millis();
if (DConUp == false) DCwaiting = true;
else {
event = 2;
DConUp = false;
DCwaiting = false;
singleOK = false;
}
}
}
// Test for normal click event: DCgap expired
if ( buttonVal == LOW && (millis() - upTime) >= DCgap && DCwaiting == true && DConUp == false && singleOK == true) {
event = 1;
DCwaiting = false;
}
// Test for hold
if (buttonVal == HIGH && (millis() - downTime) >= holdTime) {
// Trigger "normal" hold
if (not holdEventPast) {
event = 3;
waitForUp = true;
ignoreUp = true;
DConUp = false;
DCwaiting = false;
//downTime = millis();
holdEventPast = true;
}
// Trigger "long" hold
if ((millis() - downTime) >= longHoldTime) {
if (not longHoldEventPast) {
event = 4;
longHoldEventPast = true;
}
}
}
buttonLast = buttonVal;
return event;
}
//
int getLight(int samples, int sampleInterval) {
//int samples = 8;
//int sampleInterval = 50;
unsigned long Vorig = 0;
int sampleData[samples];
int light = 0;
/*for (int i = 0; i < samples; i++) {
sampleData[i] = analogRead(LDRPin);
light = light + sampleData[i];
delay(sampleInterval);
}*/
int i = 0;
while (i < samples) {
if (millis() - Vorig >= sampleInterval) {
Vorig = millis();
sampleData[i] = analogRead(LDRPin);
light = light + sampleData[i];
i++;
}
}
light = (light / samples);
//light = map(light, 0, 1023, 100, 0);
return light;
}