This has created an instance of the Traffic class, and stored that in a variable called traffic.
traffic = Traffic();
stomps on the definition of traffic assigning it what was returned by the constructor, which is not what you think it is.
In C++, you would new the new operator to assign what the constructor returned to a pointer. The new operator is not implemented for the Arduino, so you can't use the normal create an instance of a class process. Calling the constructor directly is not a good thing.
I came from Java programming to C++ and I am still a C newbie. I made the mistake because of the missing "new" Operator.
Im sry for annoying you with such trivial questions.
But now my program works thanks to you and the Community ^^.
#define Kpw 3200 //коэффициент пересчета импульсов счетчика #define KPtim 3600000000/Kpw //коэфф.для подсчета мощности по //длит.периода импульсов (длительности мерим в мс) #include <Wire.h> #include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,16,2);
unsigned long time;
unsigned long timeM;
unsigned long timeOld;
unsigned long PerImp;
const int pinPw = 8; //вывод для подключения оптрона счетчика эл.эн.
byte pinPwOld = 1; //старое значение состояния входа
long datD;
byte i;
//Timer2 указатель вектора прерывания по переполнению
ISR(TIMER2_OVF_vect) {
//приращение переменной
time ++;
int valpinPw = digitalRead(pinPw);
if (valpinPw == 0) {pinPwOld = 0;}
else {
if (pinPwOld == 0)
{ pinPwOld = 1;
timeM = millis();
PerImp = timeM - timeOld;
timeOld = timeM;
}
}
}
void setup() {
//для подсчета мощности
time = 0;
timeOld = millis();
PerImp = 1;
pinMode(pinPw, INPUT);
digitalWrite(pinPw, 1); // вкл внутр резистор
Serial.begin(9600);
SetupTimer2(); //прерывания таймера - подчет мощности
}
void loop() {
datD = KPtim/PerImp; //текущая потребляемая мощность
Serial.print("Power = ");
Serial.println(datD);
delay(10000);
}
lcd.init() // initialize the lcd
lcd.print("Power = ");
lcd.println(datD); ------------------'lcd' does not name a type ??????
delay(10000);
}