小弟在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.
不好意思有点杂乱
谢谢各位