I am getting this error from a code that was working 30 minutes ago. Please help!
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
HW10_fig12:165:3: error: 'lcd' does not name a type
lcd.setCursor(0,0);
^~~
HW10_fig12:166:3: error: 'lcd' does not name a type
lcd.write(pAngle);
^~~
HW10_fig12:169:3: error: 'Serial' does not name a type
Serial.println(pAngle);
^~~~~~
HW10_fig12:170:1: error: expected declaration before '}' token
}
^
Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program
Multiple libraries were found for "Wire.h"
Used: C:\Program
Multiple libraries were found for "Servo.h"
Used: C:\Program
exit status 1
'lcd' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Can you at least show your code starting from the first #include to the first 5 lines of loop()?
1 Like
LarryD
April 19, 2021, 4:13am
3
Sounds like you didn’t instantiate the ‘lcd’ object.
In the Arduino IDE, use CTRL T to format your code then copy the complete sketch .
Use the </> button from the ‘reply menu’ to attach the copied sketch.
1 Like
Here is my complete code.
#include<LiquidCrystal.h>
#include <Wire.h>
#include<Servo.h>
Servo m1;
LiquidCrystal lcd(7, 6, 9, 3, 11, 12);
const int SSPin = 10;
const int CS = 8;
long t;
const int xPot = A0;
const int m1Pin = 5;
int xVal, m1Val, x;
int minP = 1000, maxP = 2000;
// MPU Parameters
const int mpu = 0x68;
const int pwr = 0x6B;
const int grt = 0x1B;
const int art = 0x1C;
const int axH = 0x3B;
const int gxH = 0x43;
float ax, ay, az, at;
float gx, gxA;
float axA, ayA, azA;
float pG;
float pA;
float pAngle;
float as = 8192.00;
float gs = 131.00;
float limit = 2500.00;
// Time Parameters
float ts = 0.004;
float tL = 0.0;
float tc = 0.0;
float dt = 0.0;
// FO LPF/HPF Parameters
float fc = 1.0, h = 0.01;
float wc = 2 * PI * fc, a = 1 - wc * h, b = wc * h;
float pAf, pGf, pGL;
void setup()
{
Serial.begin(115200);
lcd.begin(16, 2);
//_____________SD shield
//_________________motor
Wire.begin();
pinMode(m1Pin, OUTPUT);
m1.attach(m1Pin, minP, maxP);
Serial.begin(115200);
// Setting MPU Parameters
Wire.beginTransmission(mpu);
Wire.write(pwr);
Wire.write(0x00); //
Wire.endTransmission();
Wire.beginTransmission(mpu);
Wire.write(grt);
Wire.write(0x00);
Wire.endTransmission();
Wire.beginTransmission(mpu);
Wire.write(art);
Wire.write(0x08);
Wire.endTransmission();
// Calibrating Gyroscope
for (int i = 0; i < limit; i++)
{
Wire.beginTransmission(mpu);
Wire.write(gxH);
Wire.endTransmission();
Wire.requestFrom(mpu, 2);
gx = Wire.read() << 8 | Wire.read();
gx /= gs;
gxA += gx;
}
gxA /= limit;
}
void loop()
{
//___________
//xVal = analogRead(xPot);
//xVal = constrain(xVal, 0, 1023);
m1Val = int(30);
m1.write(m1Val);
Serial.println(m1Val);
Serial.print("\t");
tc = millis() / 1000.00;
dt = tc - tL;
if (dt >= ts)
{
// Gyroscope Angle
Wire.beginTransmission(mpu);
Wire.write(gxH);
Wire.endTransmission();
Wire.requestFrom(mpu, 2);
gx = Wire.read() << 8 | Wire.read();
gx /= gs;
gx -= gxA;
pG += gx * dt;
pGf = a * pGf + pG - pGL;
pGL = pG;
tL = tc;
// Accelerometer Angle
Wire.beginTransmission(mpu);
Wire.write(axH);
Wire.endTransmission();
Wire.requestFrom(mpu, 6);
ax = Wire.read() << 8 | Wire.read();
ay = Wire.read() << 8 | Wire.read();
az = Wire.read() << 8 | Wire.read();
ax /= as;
ay /= as;
az /= as;
at = sqrt(ax * ax + ay * ay + az * az);
pA = asin(ay / at) * 180.0 / PI;
pA += 0.1;
pAf = a * pAf + b * pA;
// Complimentary Filter
pAngle = pAf + pGf;
}
//_________SD____
}
//_____LCD____
lcd.setCursor(0, 0);
lcd.write(pAngle);
//Serial.print(pA); Serial.print("\t");
//Serial.print(pG); Serial.print("\t");
Serial.println(pAngle);
}```
You've got orphan code at the end of loop:
}
//_____LCD____
lcd.setCursor(0, 0);
lcd.write(pAngle);
//Serial.print(pA); Serial.print("\t");
//Serial.print(pG); Serial.print("\t");
Serial.println(pAngle);
}
The top brace in this snippet closes loop. Everything below it is an orphan.
1 Like
Wow I feel stupid, I checked for this at least 3 times.... Thank you so much
system
Closed
August 17, 2021, 4:26am
7
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.