This topic has been deleted. Only users with topic management privileges can see it.
Find the code below. What i am doing wrong. The similar code works in plain GCC compliling. Brings the error close() was not declared in this scope. The same for write() . open() is Ok.
@#ifndef KSEG_DH
#define KSEG_DH
#include «QtGlobal»
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include </usr/include/sys/io.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include </usr/include/sys/fcntl.h>
#include </usr/include/linux/mtio.h>
…..
#include «KSEG_D.h»
…..
int KSEG_D::CloseOutTape()
{
close( idOutTape );
return 0;
}@
Do you mind to enlighten us and tell us the tool chain where the compile fails?
Exactly.
@#include </usr/include/sys/io.h>@
is not a good idea:-) The compiler checks all the include pathes for the files you give and /usr/include is in the list of include pathes on any decent unix-based system. sys/types.h is already found and most likely located right next to sys/io.h.
Are you planing on asking here about each and every method you need to include somewhere? You were the guy that asked about ioctl before, aren’t you? Please check the documentation of the methods you use for the include files needed (or check /usr/include manually, or read a book, or check the working non-Qt code you have).
Thank you. You are so kind. I never asked if i am not sure that i tryed everything i can find out. Some people not so smart and need help
Ok, sorry if I was patronizing, but your question led me to believe that you did none of the following:
check the documentation, e.g. by doing «man 2 close» to get the man page (assuming you are on a unix-oid OS, going by you including /usr/include)?
check a book on C programming. close/open/write/read are pretty well described in any of them. C++ books on the other hand tend to not cover them to extensively since C++ provides more high level directives for file handling. Qt has some even more high level classes for that, too.
google for «close function in linux»? That gets you the man page as the first hit.
run «grep write /usr/include»? That will get you lots of hits, so that is most likely not the preferred way to go;-)
Thank you. I was out of the office, so can not reply promptly. The problem solved. Brief description:
- I could not find ioctl.h. It was really stupid error – I was testing the application on Widows platform that is not proper for ioctl
- The error aroused during compilation as close() ( read(), write() ) is not defined. In Linux to use this in *.cpp mtio.h needs to be included.
SergeyKagen 3 / 4 / 2 Регистрация: 02.04.2018 Сообщений: 315 |
||||
1 |
||||
19.04.2019, 22:16. Показов 132281. Ответов 14 Метки нет (Все метки)
Простой код, но Arduino IDE напрочь отказывается принимать переменные. Что за глюк или я что-то неправильно делаю?
ошибка при компиляции «‘count’ was not declared in this scope», что не так?
__________________
0 |
marat_miaki 495 / 389 / 186 Регистрация: 08.04.2013 Сообщений: 1,688 |
||||
19.04.2019, 23:26 |
2 |
|||
Решение
1 |
Lavad 0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
||||||||
14.09.2019, 22:33 |
3 |
|||||||
Доброго времени суток!
В loop() делаю вызов:
При компиляции выделяется этот вызов, с сообщением: ‘myDisplay’ was not declared in this scope Замучился искать инфу о декларации/обьявлении функции. Везде, что находил, понимал одно: если ты вызываешь функцию, это и есть обьявление функции P.S. Код, что использовал в качестве функции, работоспособен. Раньше находился в loop(). Скетч постепенно разрастается, много однотипных обращений к дисплею…
0 |
8385 / 6147 / 615 Регистрация: 10.12.2010 Сообщений: 28,683 Записей в блоге: 30 |
|
14.09.2019, 23:57 |
4 |
Создал функцию (за пределами setup и loop), Перевидите на нормальный язык. В другом файле что ли? Добавлено через 1 минуту
Замучился искать инфу о декларации/обьявлении функции. Везде, что находил, понимал одно: если ты вызываешь функцию, это и есть обьявление функции Читать учебники по С++ не пробовали? https://metanit.com/cpp/tutorial/3.1.php Специфика Arduino лишь отличается тем что пред объявления не всегда нужны. Добавлено через 7 минут
0 |
ValeryS Модератор 8759 / 6549 / 887 Регистрация: 14.02.2011 Сообщений: 22,972 |
||||
15.09.2019, 00:09 |
5 |
|||
Везде, что находил, понимал одно: если ты вызываешь функцию, это и есть обьявление функции это где ж такое написано?
а объявить уже в удобном месте
0 |
0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
|
15.09.2019, 00:48 |
6 |
Неделю назад ВПЕРВЫЕ включил Arduino Uno. Написал на том же языке, что и читал на всяких форумах и справочниках по Arduino :-). За пределами этих функций — значит не внутри них. Обе приведенных Вами ссылок просмотрел, проверил в скетче… В итоге вылезла другая ошибка: void myDisplay(byte x, byte y, char str) тоже пробовал. Та же ошибка. Что не так на этот раз?
0 |
Модератор 8759 / 6549 / 887 Регистрация: 14.02.2011 Сообщений: 22,972 |
|
15.09.2019, 01:26 |
7 |
В итоге вылезла другая ошибка: точку с запятой в конце поставил?
1 |
Lavad 0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
||||||||||||
15.09.2019, 08:46 |
8 |
|||||||||||
Вот скетч. Проще некуда.
Любое из трех так называемых «объявлений» (строки 7…9) выдает одну и ту же ошибку — я пытаюсь объявить функцию как переменную. Добавлено через 9 минут
Компилятор задумался (я успел обрадоваться), но, зараза :-), он снова поставил свой автограф undefined reference to `myDisplay(unsigned char, unsigned char, char, float) На этот раз он пожаловался на строку вызова функции. Добавлено через 34 минуты
Dispay вместо Display Добавлено через 8 минут
0 |
ValeryS Модератор 8759 / 6549 / 887 Регистрация: 14.02.2011 Сообщений: 22,972 |
||||||||
15.09.2019, 10:36 |
9 |
|||||||
void myDisplay(byte, byte, char, float) = 0; вот так не надо делать(приравнивать функцию к нулю) Добавлено через 5 минут
void myDispay(byte x, byte y, char str, float temp)
myDisplay(0, 0, «C», temp); просишь чтобы функция принимала символ
или проси передавать строку, например так
1 |
Avazart 8385 / 6147 / 615 Регистрация: 10.12.2010 Сообщений: 28,683 Записей в блоге: 30 |
||||
15.09.2019, 12:02 |
10 |
|||
Кроме того наверное лучше так:
Тогда можно будет вынести ф-цию в отдельный файл/модуль.
1 |
locm |
15.09.2019, 21:07
|
Не по теме:
Arduino Uno.
AVR (Basic, немного Assembler). Arduino Uno это AVR, для которого можете писать на бейсике или ассемблере.
0 |
Avazart |
15.09.2019, 21:21
|
Не по теме:
Arduino Uno это AVR, для которого можете писать на бейсике или ассемблере. Но лучше не надо …
0 |
Lavad 0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
||||
16.09.2019, 12:12 |
13 |
|||
это где ж такое написано? Оказалось, что я верно понял чтиво по справочникам:
вот так не надо делать(приравнивать функцию к нулю)… Методом проб и ошибок уже понял :-).
или передавай символ… Если передаю в одинарных кавычках более одного символа, а функция ждет как
или проси передавать строку, например так… Буквально вчера попалось это в справочнике, но как-то не дошло, что тоже мой вариант :-).
Кроме того наверное лучше так:
Тогда можно будет вынести ф-цию в отдельный файл/модуль. Благодарю за совет! Как-нибудь проверю…
0 |
8385 / 6147 / 615 Регистрация: 10.12.2010 Сообщений: 28,683 Записей в блоге: 30 |
|
16.09.2019, 12:54 |
14 |
Оказалось, что я верно понял чтиво по справочникам: если ты вызываешь функцию, это и есть обьявление функции Нафиг выкиньте эти справочники.
0 |
0 / 0 / 0 Регистрация: 03.10.2015 Сообщений: 25 |
|
16.09.2019, 13:00 |
15 |
Ссылки Ваши добавлены в закладки. Время от времени заглядываю.
0 |
лови:
/*
Лабораторный блок питания под управлением arduino
Версия 2 (26.02.2015)
Для дополнительной информации посетите http://start.net.ua/blog/lab_power_arduino/
*/
#include <LiquidCrystal.h>;
#include <EEPROM.h>
LiquidCrystal lcd(11, 6, 5, 4, 3, 2); //rs, e, d4, d5, d6, d7
// задаем константы
float umax = 17.00; //максимальное напряжение
float umin = 0.00; //минимальное напряжение
float ah = 0.0000; //Cчетчик Ампер*часов
const int down = 10; //выход валкодера 1/2
const int up = 8; //выход валкодера 2/2
const int pwm = 9; //выход ШИМ
const int power = 7; //управление релюхой
long previousMillis = 0; //храним время последнего обновления дисплея
long maxpwm = 0; //циклы поддержки максимального ШИМ
long interval = 500; // интервал обновления информации на дисплее, мс
int mig = 0; //Для енкодера (0 стоим 1 плюс 2 минус)
float level = 0; //»уровень» ШИМ сигнала
float com = 100;
long com2 = 0;
int mode = 0;//режим (0 обычный, спабилизация тока, защита по току)
int mode1 = 0;
float Ioutmax = 1.0; //заданный ток
int set = 0; //пункты меню, отображение защиты…
int knopka_a = 0; //состояние кнопок
int knopka_b = 0;
int knopka_ab = 0;
boolean off = false;
boolean red = false;
boolean blue = false;
float counter = 5; // переменная хранит заданное напряжение
int disp = 0; //режим отображения 0 ничего, 1 мощьность, 2 режим, 3 установленный ток, 4 шим уровень
float Uout ; //напряжение на выходе
const int Pin=A2; // номер выхода, подключенного к реле
int PinState = LOW; // этой переменной устанавливаем состояние реле
long previousMillis1 = 0; // храним время последнего переключения реле
long interval1 = 1000; // интервал между включение/выключением реле (1 секунда)
long interval2 = 500;
int incomingByte;
void EEPROM_float_write(int addr, float val) // запись в ЕЕПРОМ
{
byte *x = (byte *)&val;
for(byte i = 0; i < 4; i++) EEPROM.write(i+addr, x[i]);
}
float EEPROM_float_read(int addr) // чтение из ЕЕПРОМ
{
byte x[4];
for(byte i = 0; i < 4; i++) x[i] = EEPROM.read(i+addr);
float *y = (float *)&x;
return y[0];
}
void setup() {
cli();
DDRB |= 1<<1 | 1<<2;
PORTB &= ~(1<<1 | 1<<2);
TCCR1A = 0b00000010;
//TCCR1A = 0b10100010;
TCCR1B = 0b00011001;
ICR1H = 255;
ICR1L = 255;
sei();
int pwm_rez = 13;
pwm_rez = pow(2, pwm_rez);
ICR1H = highByte(pwm_rez);
ICR1L = lowByte(pwm_rez);
// задаем режим выхода для порта, подключенного к реле
pinMode(Pin, OUTPUT);
Serial.begin(9600);
pinMode(pwm, OUTPUT);
pinMode(down, INPUT);
pinMode(up, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
pinMode(power, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
// поддерживаем еденицу на входах от валкодера
digitalWrite(up, 1);
digitalWrite(down, 1);
//поддерживаем еденицу на контактах кнопок
digitalWrite(12, 1);
digitalWrite(13, 1);
//запуск дисплея
lcd.begin(16, 2);
lcd.print(» WELCOME! «);
//загружаем настройки из памяти МК
counter = EEPROM_float_read(0);
Ioutmax = EEPROM_float_read(4);
mode = EEPROM_float_read(12);
disp = EEPROM_float_read(10);
//Если в памяти еще нет настроек — задаем что нибудь кроме нулей
if(counter==0) counter = 5; //5 вольт
if(Ioutmax==0) Ioutmax = 2; //2 ампера
//включаем реле
digitalWrite(power, 1);
}
//функции при вращении енкодера
void uup(){ //енкодер +
if(set==0){//обычный режим — добавляем напряжения
if(counter<umax) {
counter = counter+0.1;//добавляем
}
}
if(set==1){ //переключаем режим работы вперед
mode = mode+1;
if(mode>2) mode=2;
}
if(set==2){ //переключаем режим работы вперед (ON)
mode1 = mode1+1;
if(mode1>1) mode1=1;
}
if(set==3){ //настройка тока, добавляем ток
iplus();
}
if(set==4){//сброс счетчика А*ч
ah = 0;
set = 0;
disp = 5;
}
if(set==5){//сохранение текущих настроек в память
save();
}
}
void udn(){ //валкодер —
if(set==0){
if(counter>umin+0.1)counter = counter-0.1; //убавляем напнряжение
}
if(set==1){
mode = mode-1; //переключаем режим работы назад
if(mode<0) mode=0;
}
if(set==2){ //переключаем режим работы назад (OFF)
mode1 = mode1-1;
if(mode1<0) mode1=0;
}
if(set==3){//убавляем ток
iminus();
}
}
void iplus(){
Ioutmax = Ioutmax+0.01;
if(Ioutmax>0.2) Ioutmax=Ioutmax+0.04;
if(Ioutmax>1) Ioutmax=Ioutmax+0.05;
if(Ioutmax>8.00) Ioutmax=8.00;
}
void iminus(){
Ioutmax = Ioutmax-0.01;
if(Ioutmax>0.2) Ioutmax=Ioutmax-0.04;
if(Ioutmax>1) Ioutmax=Ioutmax-0.05;
if(Ioutmax<0.03) Ioutmax=0.03;
}
void save(){
lcd.clear();
lcd.setCursor (0, 0);
lcd.print(» S A V E — OK «);
EEPROM_float_write(0, counter);
EEPROM_float_write(4, Ioutmax);
EEPROM_float_write(12, mode);
EEPROM_float_write(10, disp);
//мигаем светодиодами
digitalWrite(A4, 1);
digitalWrite(A5, 1);
delay(500);
digitalWrite(A4, 0);
digitalWrite(A5, 0);
set = 0; //выходим из меню
}
void loop() //основной цикл работы МК
{
// здесь будет код, который будет работать постоянно
// и который не должен останавливаться на время между переключениями свето
unsigned long currentMillis1 = millis();
//проверяем не прошел ли нужный интервал, если прошел то
if((currentMillis1 — previousMillis1 > interval1)&(mode1==1)) {
// сохраняем время последнего переключения
previousMillis1 = currentMillis1;
// если светодиод не горит, то зажигаем, и наоборот
if (PinState == LOW)
PinState = HIGH;
else
PinState = LOW;
// устанавливаем состояния выхода, чтобы включить или выключить светодиод
digitalWrite(Pin, PinState);
}
unsigned long currentMillis = millis();
/* Вншнее управление */
if (Serial.available() > 0) { //если есть доступные данные
// считываем байт
incomingByte = Serial.read();
}else{
incomingByte = 0;
}
if(incomingByte==97){ //a
if(counter>umin+0.1)counter = counter-0.1; //убавляем напнряжение
}
if(incomingByte==98){ //b
if(counter<umax) counter = counter+0.1;//добавляем
}
if(incomingByte==99){ //c
iminus();
}
if(incomingByte==100){ //d
iplus();
}
if(incomingByte==101) mode = 0;
if(incomingByte==102) mode = 1;
if(incomingByte==103) mode = 2;
if(incomingByte==104) mode1 = 1;
if(incomingByte==105) save();
if(incomingByte==106){
digitalWrite(power, 1); //врубаем реле если оно было выключено
delay(100);
digitalWrite(A4, 0); //гасим красный светодиод
Serial.print(‘t’);
Serial.print(0);
Serial.print(‘;’);
off = false;
set = 0;//выходим из меню
}
if(incomingByte==107) off = true;
if(incomingByte==108) ah = 0;
/* конец внешнего управления */
//получаем значение напряжения и тока в нагрузке
//float Ucorr = 0.00; //коррекция напряжения, при желании можно подстроить
//float Uout = analogRead(A1) * ((5.0 + Ucorr) / 1023.0) * 5.0; //узнаем напряжение на выходе
float Uout = analogRead(A1) * (5.0 / 1023.0) * 5.0; //узнаем напряжение на выходе
float Iout = analogRead(A0) / 100.00; // узнаем ток в нагрузке
//if(Iout==0.01) Iout = 0.03; else
//if(Iout==0.02) Iout = 0.04; else
//if(Iout==0.03) Iout = 0.05; else
//if(Iout==0.04) Iout = 0.06; else
//if(Iout>=0.05) Iout = Iout + 0.02;
//if(Iout>=0.25)Iout = Iout + 0.01;
//if(Iout>=1)Iout = Iout * 1.02;
/* ЗАЩИТА и выключение */
if (((Iout>(counter+0.3)*2.0) | Iout>10.0 | off) & set<4 & millis()>100 ) // условия защиты
{
digitalWrite(power, 0); //вырубаем реле
level = 0; //убираем ШИМ сигнал
digitalWrite(A4, 1);
Serial.print(‘I0;U0;r1;W0;’);
Serial.println(‘ ‘);
set = 6;
}
//Зашита от длительного максимального шим
if (level==8190 & off==false)
{
if(set<4)//если уже не сработала защита
{
maxpwm++; //добавляем +1 к счетчику
digitalWrite(A4, 1); //светим красным для предупреждения о максимальном ШИМ
}
}
else //шим у нас не максимальный, поэтому поубавим счетчик
{
maxpwm—;
if(maxpwm<0)//если счетчик дошел до нуля
{
maxpwm = 0; //таким его и держим
if(set<4) digitalWrite(A4, 0); // гасим красный светодиод. Перегрузки нет.
}
}
/* ЗАЩИТА КОНЕЦ */
// считываем значения с входа валкодера
boolean regup = digitalRead(up);
boolean regdown = digitalRead(down);
if(regup<regdown) mig = 1; // крутится в сторону увеличения
if(regup>regdown) mig = 2; // крутится в сторону уменшения
if(!regup & !regdown) //момент для переключения
{
if(mig==1) uup();//+
if(mig==2) udn(); //-
mig = 0; //сбрасываем указатель направления
}
if(mode==0 | mode==1) //если управляем только напряжением (не режим стабилизации тока)
{
//Сравниваем напряжение на выходе с установленным, и принимаем меры..
if(Uout>counter)
{
float raz = Uout — counter; //на сколько напряжение на выходе больше установленного…
if(raz>0.05)
{
level = level — raz * 20; //разница большая управляем грубо и быстро!
}else{
if(raz>0.015) level = level — raz * 3 ; //разница небольшая управляем точно
}
}
if(Uout<counter)
{
float raz = counter — Uout; //на сколько напряжение меньше чем мы хотим
if(raz>0.05)
{
level = level + raz * 20; //грубо
}else{
if(raz>0.015) level = level + raz * 3 ; //точно
}
}
if(mode==1&&Iout>Ioutmax) //режим защиты по току, и он больше чем мы установили
{
digitalWrite(power, 0); //вырубаем реле
Serial.print(‘t’);
Serial.print(2);
Serial.print(‘;’);
//зажигаем красный светодиод
digitalWrite(A4, 1);
level = 0; //убираем ШИМ сигнал
set=5; //режим ухода в защиту…
}
}else{ //режим стабилизации тока
if(Iout>=Ioutmax)
{
//узнаем запас разницу между током в нагрузке и установленным током
float raz = (Iout — Ioutmax);
if(raz>0.3) //очень сильно превышено (ток больше заданного более чем на 0,3А)
{
level = level — raz * 20; //резко понижаем ШИМ
}else{
if(raz>0.05) //сильно превышено (ток больше заданного более чем на 0,1А)
{
level = level — raz * 5; //понижаем ШИМ
}else{
if(raz>0.00) level = level — raz * 2; //немного превышен (0.1 — 0.01А) понижаем плавно
}
}
//зажигаем синий светодиод
digitalWrite(A5, 1);
}else{ //режим стабилизации тока, но ток у нас в пределах нормы, а значит занимаемся регулировкой напряжения
digitalWrite(A5, 0);//синий светодиод не светится
//Сравниваем напряжение на выходе с установленным, и принимаем меры..
if(Uout>counter)
{
float raz = Uout — counter; //на сколько напряжение на выходе больше установленного…
if(raz>0.1)
{
level = level — raz * 20; //разница большая управляем грубо и быстро!
}else{
if(raz>0.015) level = level — raz * 5; //разница небольшая управляем точно
}
}
if(Uout<counter)
{
float raz = counter — Uout; //на сколько напряжение меньше чем мы хотим
float iraz = (Ioutmax — Iout); //
if(raz>0.1 & iraz>0.1)
{
level = level + raz * 20; //грубо
}else{
if(raz>0.015) level = level + raz ; //точно
}
}
}
}//конец режима стабилизации тока
if(off) level = 0;
if(level<0) level = 0; //не опускаем ШИМ ниже нуля
if(level>8190) level = 8190; //не поднимаем ШИМ выше 13 бит
//Все проверили, прощитали и собственно отдаем команду для силового транзистора.
if(ceil(level)!=255) analogWrite(pwm, ceil(level)); //подаем нужный сигнал на ШИМ выход (кроме 255, так как там какая-то лажа)
/* УПРАВЛЕНИЕ */
if (digitalRead(13)==0 && digitalRead(12)==0 && knopka_ab==0 ) { // нажата ли кнопка a и б вместе
knopka_ab = 1;
//ah = 0.000;
knopka_ab = 0;
}
if (digitalRead(13)==0 && knopka_a==0) { // нажата ли кнопка А (disp)
knopka_a = 1;
disp = disp + 1; //поочередно переключаем режим отображения информации
if(disp==6) disp = 0; //дошли до конца, начинаем снова
}
if (digitalRead(12)==0 && knopka_b==0) { // нажата ли кнопка Б (menu)
knopka_b = 1;
set = set+1; //
if(set>5 | off) {//Задействован один из режимов защиты, а этой кнопкой мы его вырубаем. (или мы просто дошли до конца меню) //количество меню
off = false;
digitalWrite(power, 1); //врубаем реле если оно было выключено
delay(100);
digitalWrite(A4, 0); //гасим красный светодиод
Serial.print(‘t’);
Serial.print(0);
Serial.print(‘;’);
Serial.print(‘r’);
Serial.print(0);
Serial.print(‘;’);
Serial.println(‘ ‘);
set = 0;//выходим из меню
}
lcd.clear();//чистим дисплей
}
//сбрасываем значения кнопок или чего-то вроде того.
if(digitalRead(12)==1&&knopka_b==1) knopka_b = 0;
if(digitalRead(13)==1&&knopka_a==1) knopka_a = 0;
/* COM PORT */
if(currentMillis — com2 > com) {
// сохраняем время последнего обновления
com2 = currentMillis;
//Считаем Ампер*часы
ah = ah + (Iout / 36000);
Serial.print(‘U’);
Serial.print(Uout);
Serial.print(‘;’);
Serial.print(‘I’);
Serial.print(Iout);
Serial.print(‘;’);
Serial.print(‘i’);
Serial.print(Ioutmax);
Serial.print(‘;’);
Serial.print(‘u’);
Serial.print(counter);
Serial.print(‘;’);
Serial.print(‘W’);
Serial.print(level);
Serial.print(‘;’);
Serial.print(‘c’);
Serial.print(ah);
Serial.print(‘;’);
Serial.print(‘m’);
Serial.print(mode);
Serial.print(‘;’);
Serial.print(‘r’);
Serial.print(digitalRead(A4));
Serial.print(‘;’);
Serial.print(‘b’);
Serial.print(digitalRead(A5));
Serial.print(‘;’);
Serial.println(‘ ‘);
}
/* ИНДИКАЦИЯ LCD */
if(set==0){
//стандартный екран
//выводим уснановленное напряжение на дисплей
lcd.setCursor (0, 1);
lcd.print(«U>»);
if(counter<10) lcd.print(» «); //добавляем пробел, если нужно, чтобы не портить картинку
lcd.print (counter,1); //выводим установленное значение напряжения
lcd.print («V «); //пишем что это вольты
//обновление информации
/*проверяем не прошел ли нужный интервал, если прошел то
выводим реальные значения на дисплей*/
if(currentMillis — previousMillis > interval) {
// сохраняем время последнего обновления
previousMillis = currentMillis;
//выводим актуальные значения напряжения и тока на дисплей
lcd.setCursor (0, 0);
lcd.print(«U=»);
if(Uout<9.99) lcd.print(» «);
lcd.print(Uout,2);
lcd.print(«V I=»);
lcd.print(Iout, 2);
lcd.print(«A «);
//дополнительная информация
lcd.setCursor (8, 1);
if(disp==0){ //ничего
lcd.print(» «);
}
if(disp==1){ //мощьность
lcd.print(» «);
lcd.print (Uout * Iout,2);
lcd.print(«W «);
}
if(disp==2){ //режим БП
if(mode==0)lcd.print («standart»);
if(mode==1)lcd.print («shutdown»);
if(mode==2)lcd.print (» drop»);
}
if(disp==3){ //режим БП
if(mode1==0) lcd.print(«Off»);
if(mode1==1) lcd.print(«On «);
}
if(disp==4){ //максимальный ток
lcd.print (» I>»);
lcd.print (Ioutmax, 2);
lcd.print («A «);
}
if(disp==5){ // значение ШИМ
lcd.print («pwm:»);
lcd.print (ceil(level), 0);
lcd.print (» «);
}
if(disp==6){ // значение ШИМ
if(ah<1){
//if(ah<0.001) lcd.print (» «);
if(ah<=0.01) lcd.print (» «);
if(ah<=0.1) lcd.print (» «);
lcd.print (ah*1000, 1);
lcd.print («mAh «);
}else{
if(ah<=10) lcd.print (» «);
lcd.print (ah, 3);
lcd.print («Ah «);
}
}
}
}
/* ИНДИКАЦИЯ МЕНЮ */
if(set==1)//выбор режима
{
lcd.setCursor (0, 0);
lcd.print(«> MENU 1/5 «);
lcd.setCursor (0, 1);
lcd.print(«mode: «);
//режим (0 обычный, спабилизация тока, защита по току)
if(mode==0) lcd.print(«normal «);
if(mode==1) lcd.print(«shutdown «);
if(mode==2) lcd.print(«drop «);
}
if(set==2){//настройка сульфатации
lcd.setCursor (0, 0);
lcd.print(«> MENU 2/5 «);
lcd.setCursor (0, 1);
lcd.print(«DeSulfat: «);
if(mode1==0) lcd.print(«Off»);
if(mode1==1) lcd.print(«On «);
}
if(set==3){//настройка тока
lcd.setCursor (0, 0);
lcd.print(«> MENU 3/5 «);
lcd.setCursor (0, 1);
lcd.print(«I out max: «);
lcd.print(Ioutmax);
lcd.print(«A»);
}
if(set==4){//спрашиваем хочет ли юзер сохранить настройки
lcd.setCursor (0, 0);
lcd.print(«> MENU 4/5 «);
lcd.setCursor (0, 1);
lcd.print(«Reset A*h? ->»);
}
if(set==5){//спрашиваем хочет ли юзер сохранить настройки
lcd.setCursor (0, 0);
lcd.print(«> MENU 5/5 «);
lcd.setCursor (0, 1);
lcd.print(«Save options? ->»);
}
/* ИНДИКАЦИЯ ЗАЩИТЫ */
if(set==6){//защита. вывод инфы
lcd.setCursor (0, 0);
lcd.print(«ShutDown! «);
lcd.setCursor (0, 1);
lcd.print(«Iout»);
lcd.print(«>Imax(«);
lcd.print(Ioutmax);
lcd.print(«A)»);
level=0;
Serial.print(‘I0;U0;r1;W0;’);
Serial.println(‘ ‘);
}
if(set==7){//защита. вывод инфы критическое падение напряжения
Serial.print(‘I0;U0;r1;W0;’);
digitalWrite(A4, true);
Serial.println(‘ ‘);
level=0;
lcd.setCursor (0, 0);
if (off==false){ lcd.print(«[ OVERLOAD ]»);
lcd.setCursor (0, 1);
//и обьясняем юзеру что случилось
if((Iout>(counter+0.3)*2.0) | Iout>10.0){
Serial.print(‘t’);
Serial.print(1);
Serial.print(‘;’);
lcd.print(» Iout >= Imax «);
}
}else{
lcd.print(«[ OFF ]»);
lcd.setCursor (0, 1);
Serial.print(‘t’);
Serial.print(4);
Serial.print(‘;’);
}
}
}
Table of Contents
Common G++ Errors
Summary
This is a guide to help you CS35ers make sense of g++ and its often cryptic error messages.
If you discover an error not listed here feel free to edit this wiki,
or send your error along with source code and an explanation to me — grawson1@swarthmore.edu
Weird Errors
If you are getting strange compiler errors when your syntax looks fine, it might be a good idea to check that your Makefile is up to date
and that you are including the proper .h files. Sometimes a missing } or ; or ) will yield some scary errors as well.
Lastly, save all files that you might have changed before compiling.
Bad Code Sample
What’s wrong with the following code? (Hint: there are two errors)
#include<iostream> using namespace std; int main(){ int foo; for(int i = 0, i<100, i++) { foo++; cout << foo << endl; } return 0; }
When compiled this yields:
junk.cpp:9: error: expected initializer before '<' token
junk.cpp:13: error: expected primary-expression before 'return
‘
junk.cpp:13: error: expected `;' before 'return
‘
junk.cpp:13: error: expected primary-expression before 'return
‘
junk.cpp:13: error: expected `)' before 'return
‘
First, the parameters of the for
loop need to be separated by semicolons, not commas.
for(int i = 0; i<100; i++) { foo++; cout << foo << endl; }
Now look at this sample output of the corrected code:
-1208637327
-1208637326
-1208637325
-1208637324
-1208637323
-1208637322
Why the weird values? Because we never initialized foo
before incrementing it.
int foo = 0;
‘cout’ was not declared in this scope
Two things to check here:
(1) Did you add
#include<iostream>
to your list of headers?
(2) Did you add
using namespace std;
after your #includes?
‘printf’ was not declared in this scope
Add
#include<cstdio>
to your list of headers. Note if you are coming from C programming, adding
#include<cstdio> is preferred in C++ over #include <stdio.h>.
Cannot Pass Objects of non-POD Type
junk.cpp:8: warning: cannot pass objects of non-POD type 'struct std::string' through '…'; call will abort at runtime
junk.cpp:8: warning: format '%s' expects type 'char*', but argument 2 has type 'int
‘
What this usually means is that you forgot to append .c_str() to the name of your string variable when using printf.
This error occurred when trying to compile the following code:
int main(){ string foo = "dog"; printf("This animal is a %s.n",foo); return 0; }
Simply appending to .c_str() to “foo” will fix this:
printf("This animal is a %s.n",foo.c_str());
The reason you got this error is because printf is a C function and C handles strings differently than C++
Invalid Use of Member
junk.cpp:8: error: invalid use of member (did you forget the '&' ?)
What this usually means is that you forget to add () to the end of a function call.
Ironically, every time I see this it is never because I forgot the ‘&’.
This error occurred when trying to compile the following code:
int main(){ string foo = "dog"; printf("This animal is a %s.n",foo.c_str); return 0; }
Simply adding the open and close parentheses () will take care of this for you:
printf("This animal is a %s.n",foo.c_str());
Request for Member ‘Foo’ in ‘Bar’, which is of non-class type ‘X’
trycredit.cpp:86: error: request for member 'print' in 'card', which is of non-class type 'CreditCard*
‘
What this usually means is that you are using a ‘.’ between the class pointer and the function you are trying to call.
Here is an example from the CreditCard lab:
void useCard(CreditCard *card, int method) { //Used to access the methods of the class if (method==1) { card.print(); }
Since card
is a CreditCard* we need → rather than . Fixed:
if (method==1) { card->print(); }
Undefined Reference to V Table
This error usually means you need to add a destructor to your myClass.cpp/myClass.inl code.
If you don’t want to implement a real destructor at this point, you can write something like this:
myClass::~myClass(){}
So long as the destructor exists, you should now be able to compile fine. Of course,
implement a real destructor at a later point.