I am in a robotics class and we are working with Arduino Uno R3 boards with Adafruit motors shields. We are trying to use encoders to calibrate the power of slave motors based on master motor rotation, but I cannot upload to the board because of the following error:
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\KSCHUT~1\AppData\Local\Temp\ccQRXTjR.ltrans0.ltrans.o: In function `main':
C:\Users\kschutt19\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.20\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Also, nothing has been highlighted in the code as an error.
-I have reinstalled the Arduino IDE on my computer
-I have reset my board
-I have tried a different USB cable
-I have tried uploading to a different board on another robot
-I have copied/pasted the code and emailed it to another computer, then tried to download to my board
Here is the code:
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
int LEncoder = 4;
int REncoder = 3;
int RCount = 0;
int LCount = 0;
int pastLeft = 0;
int pastRight = 0;
int currentLeft = 0;
int currentRight = 0;
int masterPower = 30;
int slavePower = 30;
int error = 0;
int kp = 1;
int drive = 100;
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMS.getMotor(3); //back left is M3
Adafruit_DCMotor *myMotor4 = AFMS.getMotor(4);
void setup() {
AFMS.begin();
pinMode(3, INPUT);
pinMode(4, INPUT);
delay(2000);
while (LCount <= drive && RCount <= drive){
myMotor1->setSpeed(masterPower);
myMotor2->setSpeed(slavePower);
myMotor3->setSpeed(slavePower);
myMotor4->setSpeed(masterPower);
myMotor1->run(FORWARD);
myMotor2->run(FORWARD);
myMotor3->run(FORWARD);
myMotor4->run(FORWARD);
currentLeft = digitalRead(LEncoder);
currentRight = digitalRead(REncoder);
//0 = blocked
if (pastLeft == 1 && currentLeft == 0){
pastLeft = 0;
}
else if (pastLeft == 0 && currentLeft == 1){
pastLeft = 1;
LCount = LCount +1;
}
else if (pastRight == 1 && currentRight == 0){
pastRight = 0;
}
else if (pastRight == 0 && currentRight == 1){
pastRight = 1;
RCount = RCount +1;
}
error = LCount - RCount;
slavePower += error / kp;
delay(100);
}
myMotor1->run(RELEASE);
myMotor2->run(RELEASE);
myMotor3->run(RELEASE);
myMotor4->run(RELEASE);
}
Thank you for any helpful tips!