1
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?

6
  • byte datos[3]; changed, I will test the code. I'm not sure that it will work. Because the byte of small value. May 23, 2018 at 22:51
  • 1
    it is telling you that 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 array
    – jsotola
    May 23, 2018 at 23:23
  • try this: Serial.print(datos);
    – DH12043
    May 24, 2018 at 1:25
  • See: github.com/arduino/ArduinoCore-avr/blob/…
    – per1234
    May 24, 2018 at 2:06
  • @jsotola, what? write(int)? there is write(byte) and write(buff[], size)
    – Juraj
    May 24, 2018 at 3:33

1 Answer 1

2

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).

1
  • note: sizeof returns the size of the array in bytes
    – Juraj
    May 24, 2018 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.