im trying to make a sytsem to detect vibration from sensors and then light up an led and send a signal to max8 to play a sound and when i upload the code below to the arduino uno i get this errror:
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"
C:\Users\caley\Downloads\AAI_CW2_Project_Sketch\test_final\test_final.ino: In function 'void SetLedOn(int, int*)':
C:\Users\caley\Downloads\AAI_CW2_Project_Sketch\test_final\test_final.ino:59:45: warning: 'sizeof' on array function parameter 'leds' will return size of 'int*' [-Wsizeof-array-argument]
for (int i = 1; i <= sizeof(leds); i++)
^
C:\Users\caley\Downloads\AAI_CW2_Project_Sketch\test_final\test_final.ino:57:43: note: declared here
void SetLedOn(int ledId, int leds[])
^
C:\Users\caley\AppData\Local\Temp\cc1D5F4s.ltrans0.ltrans.o: In function `main':
C:\Users\caley\OneDrive\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino/main.cpp:43: undefined reference to `setup'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
//init variables
int leds[] = { 2, 3, 4 };
int numPads = 3;
int threshold = 50;
int state = 0;
int baseTime = millis();
int thisPress = 0;
int lastPressed = 0;
void loop()
{
//if in state>0 but more than 5secs elapsed since last press then reset to state0
if( (state>0) && ( millis() > (baseTime+(5000*state))))
{
state = 0;
SetLedOn(0,leds);
}
//test for padd press
thisPress = GetPadPress(numPads, threshold);
//if pad pressed detected and different from last pad pressed then move to next state and update leds/max
if (thisPress != 0 && thisPress!=lastPressed)
{
state++; //Increment state
SetLedOn(thisPress,leds); //turn the pads corresponding led on, turn off others
Serial.println(state); //set message to MAX
//or alternatively to help in debugging
//String msgPrefix= "PadPress: ";
//String msg = msgPrefix + state;
//Serial.println(msg);
//or alternatively you could send the pad that was pressed, or send both state and pad pressed
//update the lastPressed
lastPressed = thisPress;
}
} //continue looping
int GetPadPress(int numPads, int threshold) //returns the number of the pad that was pressed, if press above threshold, otherwise returns 0
{
for (int i = 0; i < numPads; i++) //poll each pad
{
if (analogRead(i) > threshold) { return i; } //return on first detected pad press above threshold
}
return 0;
}
void SetLedOn(int ledId, int leds[])
{ //Turn on specified LED, turn off all others, to turn off all leds pass ledId=0
for (int i = 1; i <= sizeof(leds); i++)
{
if (i == ledId) { digitalWrite(leds[i], HIGH); }
else { digitalWrite(leds[i], LOW); }
}
}