int angleServo1,angleServo2 = 0;
const int axisX=A0; // ось Х подключена к A0
const int axisY=A1; // ось Y подключена к A1
int valX, valY = 0; // переменные для хранения значений осей
int datos[3];
#include <SPI.h>
void setup()
{
Serial.begin(9600);
}
void loop()
{
valX = analogRead(axisX); // значение оси Х
valY = analogRead(axisY); // значение оси Y
// масштабируем значение к интервалу 0-180
angleServo1=map(valX,0,800,100,-100);
angleServo2=map(valY,0,810,100,-100);
datos[0] = angleServo1;
datos[1] = angleServo2;
Serial.write(datos, sizeof(datos));
delay(100);
}
error: no matching function for call to 'HardwareSerial::write(int [3], unsigned int)'
how to remove an error and pass an array of bytes?
1 Answer 1
You want to send data to computer processing or print them for user to read? Functions write
send raw data. To print the data to Serial monitor print
and println
functions are used.
There are two write
functions. First sends one byte. Second sends array of bytes. There is no write function to send array of ints. You could cast the array of ints to array of bytes to send the array as raw bytes for processing on the receiving side. But then you first should perhaps send to the receiving side some control data about the data package.
Serial.write((byte*) datos, sizeof(datos));
If you want to print numbers to Serial Monitor, the print
functions have variants which take a number and convert it to string. But there is no print
function to print an array of numbers. You must print them one by one in a for loop. And put some separator between them (coma, space, new line).
-
note: sizeof returns the size of the array in bytes2018年05月24日 03:59:10 +00:00Commented May 24, 2018 at 3:59
HardwareSerial::write()
does not have a function that will accept two arguments where the first one is an array of integers and the second one is an unsigned integer ..... i think that HardwareSerial::write() only has a function that accepts one argument that is an integer, not an arraywrite(byte)
andwrite(buff[], size)