0
我試圖通過發送4個電位器值。 i2c通過另一個arduino的虛擬線路接收到這些值後。 我的設置由3個arduinos組成。 1st arduino連接到變送器和4個電位器,它通過發送值。 tx通過virtualwire。 2nd arduino由接收器組成。 3rd arduino由4個舵機組成。第二和第三個arduino通過耦合。一輛i2c巴士。 我不能發送potrentiometer的所有4個值。不過,我可以發送一個電位計的值。 這是我的素描。無法通過i2c總線發送4個電位器值
#include <VirtualWire.h>
#include <Wire.h>
int Sensor1Data; // VARIABLE WHERE THE ANALOG VALUE OF POT 1 GOT STORED BY THE TX
int Sensor2Data; // VARIABLE WHERE THE ANALOG VALUE OF POT 2 GOT STORED BY THE TX
int Sensor3Data; // VARIABLE WHERE THE ANALOG VALUE OF POT 3 GOT STORED BY THE TX
int Sensor4Data; // VARIABLE WHERE THE ANALOG VALUE OF POT 4 GOT STORED BY THE TX
int data[4];
char StringReceived[22];
void setup()
{
Wire.begin(); // START I2C (WIRE.h)
vw_setup(6000); // BAUDERATE FOR VIRTUALWIRE
vw_set_rx_pin(11); // DEFINE PIN FOR VIRTUALWIRE
vw_rx_start(); // START VIRTUALWIRE
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) { // GET THE DATA
int i;
for (i = 0; i < buflen; i++)
{ // CHECKSUM OK ? GET MESSAGE
StringReceived[i] = char(buf[i]); // FILL THE ARRAY
}
sscanf(StringReceived, "%d,%d,%d,%d,%d,%d",&Sensor1Data, &Sensor2Data,&Sensor3Data,&Sensor4Data); // Converts a string to an array
Sensor1Data = map(Sensor1Data, 0, 1023, 0, 180); // MAPS THE 8BIT SERVODATA TO SERVOMIN/MX
Sensor2Data = map(Sensor2Data, 0, 1023, 26, 160); // MAPS THE 8BIT SERVODATA TO SERVOMIN/MX
Sensor3Data = map(Sensor3Data, 0, 1023, 26, 160); // MAPS THE 8BIT SERVODATA TO SERVOMIN/MX
Sensor4Data = map(Sensor4Data, 0, 1023, 26, 160);
data[0] = Sensor1Data;
data[1] = Sensor2Data;
data[2] = Sensor3Data;
data[3] = Sensor4Data;// MAPS THE 8BIT SERVODATA TO SERVOMIN/MX
Wire.beginTransmission(8); // OPENS AN I2C ON PIN 8
Wire.write(data,4);
// SEND POT 1 VALUE TO I2C DEVICE 8
Wire.endTransmission(); // END TRANSMISSION
// SEND POT 1 VALUE TO I2C DEVICE 8
}
memset(StringReceived, 0, sizeof(StringReceived)); // RESET STRING RECEIVED
}`
這個草圖顯示
no matching function for call to 'TwoWire::write(int [4], int)'