I am currently doing a project in my degree where the use of an Arduino Uno is mandatory. I haven't had much experience with the c++ language at all. The code I have written is for a product which will have 4 LEDs that will turn on randomly and stay on until the use moves the product and the accelerometer reads above a certain threshold of acceleration.
I am currently getting an error message which I really don't understand.
The code seems to be very close to compiling (e.g. compiles for a few seconds), before the error shows.
Does anyone have any suggestions please?
Many thanks in advance.
CODE
#include <Wire.h>
#include <SparkFun_MMA8452Q.h>
int rand();
int button = 4;
int LED1 = 10;
int LED2 = 11;
int LED3 = 12;
unsigned long randomNumber; // extended variables for number storage
unsigned long time_taken; // only stores positive data
MMA8452Q accel;
int xAcceleration;
void setup()
{
accel.init();
Serial.begin(9600);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(button, INPUT);
randomSeed(analogRead(A0));
}
void rand_light()
{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
randomNumber = random(10, 13); // computing the random number
Serial.println(randomNumber);
digitalWrite(randomNumber, HIGH); // turning on the LED of the same number
acceleration();
}
void acceleration()
{
accel.read(); // Update acceleromter data
xAcceleration = accel.x;
while (xAcceleration <= 2000)
{
analogRead;
}
rand_light();
}
ERROR
/var/folders/t8/33_90srn4xj5sg6gcn2slx8h0000gn/T//ccbg7JTF.ltrans0.ltrans.o: In function `main':
/private/var/folders/t8/33_90srn4xj5sg6gcn2slx8h0000gn/T/AppTranslocation/4C23B832-9C40-4630-8F2A-1791BE626182/d/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/main.cpp:46: undefined reference to `loop'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
Final.ino (1.17 KB)