Accelerologger: More Problems With New Code!!!

This is now solved!!! Check it out what a silly mistake! NO VOID SETUP!!!!!!

Here is the new code:

#include <SparkFun_ADXL345.h>

#include <SD.h>
#include <SPI.h>

//ADXL345 adxl = ADXL345(10); For SPI Cumunication
ADXL345 adxl = ADXL345();
File myFile;
const int threshold = 1499;
const int switchPin = 7;
int switchState;
int ctr = 0;
int pinCS = 10;
int x,y,z;
int sumX, sumY, sumZ;

void loop() {
//define int x, y, z in setup instead
// also define int sumX, sumY, sumZ in setup
adxl.readAccel(&x, &y, &z);
sumX += x;
sumY += y;
sumZ += z;

switchState = digitalRead(switchPin);

if (switchState == HIGH) {
ctr++;
if (ctr > threshold) {
if (myFile) {
myFile.println(sumY/threshold);
Serial.println(sumY/threshold);
}
else {
Serial.println("error opening test.txt");
}
sumX = 0;
sumY = 0;
sumZ = 0;
ctr = 0;
}

} else //switchState != HIGH
{
myFile.close();
Serial.println("closed");
}
}

But I am having another problem it doesn’t upload it comes up with the error:

Arduino: 1.8.3 (Windows 10), Board: “Arduino Nano, ATmega328”

C:\Users\ETHANJ~1\AppData\Local\Temp\cclGBXne.ltrans1.ltrans.o: In function `main’:

C:\Program Files\Arduino\hardware\arduino\avr\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 Nano.

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

I hope we can figure out what is wrong!

EJBuilder

(P.S much thanks to Mike’s help!!!)

2 Replies to “Accelerologger: More Problems With New Code!!!”

  1. Did you try uploading a simple basic Blink example first, to check if the problem is your IDE or computer or the program that you are trying to upload?

Leave a Reply