為什麼這篇arduino程式碼合併鄉民發文收入到精華區:因為在arduino程式碼合併這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者shan83 (無盡深淵、寂靜虛空)看板ASM標題[問題] 請教程式設計時間Fri Jun 3...
小弟在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://www.ptt.cc/bbs/ASM/M.1464933014.A.6AC.html
但功能不一樣?
還是完全一樣?
所以我去函式庫砍掉一個就好了嗎?
※ 編輯: shan83 (61.230.53.137), 06/03/2016 17:02:27
※ 編輯: shan83 (61.230.53.137), 06/03/2016 22:29:02