[问题] 请教程式设计

楼主: shan83 (無盡深淵、寂靜虛空)   2016-06-03 13:50:10
小弟在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.
不好意思有点杂乱
谢谢各位
作者: chuegou (chuegou)   2016-06-03 15:25:00
...先学着看错误讯息multiple definition of `i2c_init()'你有两个一样的函式 他问你要call哪一个下面基本上都是同类型错误名称 把他注解掉虽然不是好方法.但你可以试试看不过运作起来会怎样我也不肯定
作者: felaray (傲娇鱼)   2016-06-04 21:15:00
看起来就SoftI2CMaster里面出包了.如果都引用同样的函示库,整合前应该也会出包吧
楼主: shan83 (無盡深淵、寂靜虛空)   2016-06-05 11:10:00
整合前没问题耶
作者: god145145   2016-06-05 22:05:00
把第一个i2cmaster拿掉,编译后再把缺的补回来
楼主: shan83 (無盡深淵、寂靜虛空)   2016-06-06 02:58:00
好哦我试试,谢谢

Links booklink

Contact Us: admin [ a t ] ucptt.com