作者shan83 (无尽深渊、寂静虚空)
看板ASM
标题[问题] 请教程式设计
时间Fri Jun 3 13:50:10 2016
小弟在arduino平台上做些小东西
我的程度没有很高
有一个问题想请教各位
我有两个独立的程式想要合并
函式库都有
独立编译可以过
我整合一起就GG了
可能port上会冲突
请问要怎麽解决?
那些部份需要修改吗?
请具体一点
因为我程度不高...
谢谢各位
先附我整合的程式码
#include <i2cmaster.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const float lowReading = 60;
const float highReading = 75;
const unsigned char separatorCharacter = 255;
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
Serial.begin(9600);
i2c_init();
PORTC = (1 << PORTC2) | (1 << PORTC3);
Serial.println("completed setup");
lcd.begin(16, 2);
for(int i = 0; i < 3; i++) {
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("fuck up");
delay(8000);
lcd.clear();
}
float normf(float x, float low, float high) {
float y = (x - low) * 255.f / (high - low);
if (y > 255) {
y = 255;
}
if (y < 0) {
y = 0;
}
return y;
}
void loop() {
int dev = 0x5A << 1;
int data_low = 0;
int data_high = 0;
int pec = 0;
i2c_start_wait(dev + I2C_WRITE);
i2c_write(0x07);
i2c_rep_start(dev + I2C_READ);
data_low = i2c_readAck();
data_high = i2c_readAck();
pec = i2c_readNak();
i2c_stop();
double tempFactor = 0.02;
double tempData = 0x0000;
int frac;
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor) - 0.01;
float celcius = tempData - 273.15;
float fahrenheit = (celcius * 1.8) + 32;
float state = normf(fahrenheit, lowReading, highReading);
Serial.print(celcius);
Serial.print(" degrees C,");
Serial.print(fahrenheit);
Serial.println(" degrees F");
lcd.setCursor(0, 0);
lcd.print(celcius);
lcd.print(" degrees C");
lcd.setCursor(0, 1);
lcd.print(fahrenheit);
lcd.print(" degrees F");
int r, g, b = 0;
if (fahrenheit > 92) {
r = 0;
g = 1;
b = 1;
}
else if (fahrenheit > 83) {
r = 1;
g = 0;
b = 1;
}
else {
r = 1;
g = 1;
b = 0;
}
int red = constrain((int)255 * r, 0, 255);
int green = constrain((int)255 * g, 0, 255);
int blue = constrain((int)255 * b, 0, 255);
setLedColor(red, green, blue);
}
void setLedColor(int r, int g, int b) {
analogWrite(8, r);
analogWrite(9, g);
analogWrite(10, b);
}
以下是错误讯息
Arduino:1.6.9 (Windows 10), 板子:"Arduino/Genuino Uno"
libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `i2c_init()':
C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/
SoftI2CMaster.h:267: multiple definition of `i2c_init()'
libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\
Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here
libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `ass_i2c_delay_half':
C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/
SoftI2CMaster.h:196: multiple definition of `i2c_start(unsigned char)'
libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\
Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here
libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `ass_i2c_delay_half':
C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/
SoftI2CMaster.h:196: multiple definition of `i2c_rep_start(unsigned char)'
libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\
Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here
libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `ass_i2c_delay_half':
C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/
SoftI2CMaster.h:196: multiple definition of `i2c_start_wait(unsigned char)'
libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\
Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here
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.
不好意思有点杂乱
谢谢各位
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 210.61.28.227
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/ASM/M.1464933014.A.6AC.html
1F:推 chuegou: ...先学着看错误讯息 06/03 15:25
2F:→ chuegou: multiple definition of `i2c_init()' 06/03 15:25
3F:→ chuegou: 你有两个一样的函式 他问你要call哪一个 06/03 15:26
4F:→ chuegou: 下面基本上都是同类型错误 06/03 15:27
一样的是指名称一样
但功能不一样?
还是完全一样?
所以我去函式库砍掉一个就好了吗?
※ 编辑: shan83 (61.230.53.137), 06/03/2016 17:02:27
5F:推 chuegou: 名称 把他注解掉虽然不是好方法.但你可以试试看 06/03 17:40
6F:→ chuegou: 不过运作起来会怎样我也不肯定 06/03 17:41
好的 谢谢
※ 编辑: shan83 (61.230.53.137), 06/03/2016 22:29:02
7F:推 felaray: 看起来就SoftI2CMaster里面出包了. 06/04 21:15
8F:→ felaray: 如果都引用同样的函示库,整合前应该也会出包吧 06/04 21:16
9F:→ shan83: 整合前没问题耶 06/05 11:10
10F:推 god145145: 把第一个i2cmaster拿掉,编译後再把缺的补回来 06/05 22:05
11F:→ shan83: 好哦我试试,谢谢 06/06 02:58