hi so for school I am doing an "automated house" thanks to the detection of 1,2or 3 claps turning on and off things. I found I code to help me however I really don't understand why but the command
" struct DataBlockStruct meting1,meting2; "
shows this error "aggregate 'DataBlockStruct meting1' has incomplete type and can not be defined"
jimboi:
hi so for school I am doing an "automated house" thanks to the detection of 1,2or 3 claps turning on and off things. I found I code to help me however I really don't understand why but the command
" struct DataBlockStruct meting1,meting2; "
shows this error "aggregate 'DataBlockStruct meting1' has incomplete type and can not be defined"
thanks for your help
Possible because the meting1 and meting2 do not have a data type associated with them. Did you not cut and paste the entire program?
Where have you defined struct DataBlockStruct? Or where do you think you have defined it because in reality you haven't or the compiler hasn't seen it.
oqibidipo:
Where have you defined struct DataBlockStruct? Or where do you think you have defined it because in reality you haven't or the compiler hasn't seen it.
I must admit I am not familiar with the command but I do not think I have defined Struct DataBlockStruct, here is the code if you want to further help
#define signalToRelayPin 12 #define sensorPin 7
int lastSoundValue;
int soundValue;
long lastNoiseTime = 0;
long currentNoiseTime = 0;
long lastLightChange = 0;
int relayStatus = HIGH;
if (soundValue == 1) { // if there is currently a noise
if (
(currentNoiseTime > lastNoiseTime + 200) && // to debounce a sound occurring in more than a loop cycle as a single noise
(lastSoundValue == 0) && // if it was silent before
(currentNoiseTime < lastNoiseTime + 800) && // if current clap is less than 0.8 seconds after the first clap
(currentNoiseTime > lastLightChange + 1000) // to avoid taking a third clap as part of a pattern
) {
relayStatus = !relayStatus;
Serial.println("2 X CLAP");
The sketch compiles fine without that line. Get rid of it.
const byte SignalToRelayPin = 12;
const byte SensorPin = 7;
int LastSoundValue;
unsigned long LastNoiseTime = 0;
unsigned long LastLightChange = 0;
int RelayStatus = HIGH;
void setup()
{
pinMode(SensorPin, INPUT);
pinMode(SignalToRelayPin, OUTPUT);
Serial.begin(115200);
}
// struct DataBlockStruct meting1, meting2;
void loop()
{
int soundValue = digitalRead(SensorPin);
unsigned long currentTime = millis();
if (soundValue == 1) // if there is currently a noise
{
if (
(currentTime - LastNoiseTime > 200) && // to debounce a sound occurring in more than a loop cycle as a single noise
(LastSoundValue == 0) && // if it was silent before
(currentTime - LastNoiseTime > 800) && // if current clap is less than 0.8 seconds after the first clap
(currentTime - LastLightChange > 1000) // to avoid taking a third clap as part of a pattern
)
{
RelayStatus = !RelayStatus;
Serial.println("2 X CLAP");
}
else
{
Serial.println("1 X CLAP");
}
LastNoiseTime = currentTime;
}
LastSoundValue = soundValue;
}
Note: Use local variables where possible.
Note: Use 'unsigned long' for millis() and micros() values.
Note: Always subtract older time from current time and compare to interval. Adding interval to older time can cause an overflow.
Note: I recommend initial capitals on names of global variables.
void loop()
{
int soundValue = digitalRead(SensorPin);
unsigned long currentTime = millis();
if (soundValue == 1) // if there is currently a noise
{
if (
(currentTime - LastNoiseTime > 200) && // to debounce a sound occurring in more than a loop cycle as a single noise
(LastSoundValue == 0) && // if it was silent before
(currentTime - LastNoiseTime > 800) && // if current clap is less than 0.8 seconds after the first clap
(currentTime - LastLightChange > 1000) // to avoid taking a third clap as part of a pattern
)
{
RelayStatus = !RelayStatus;
Serial.println("2 X CLAP");
}
else
{
Serial.println("1 X CLAP");
}
LastNoiseTime = currentTime;
}
LastSoundValue = soundValue;
}
Note: Use local variables where possible.
Note: Use 'unsigned long' for millis() and micros() values.
Note: Always subtract older time from current time and compare to interval. Adding interval to older time can cause an overflow.
Note: I recommend initial capitals on names of global variables.