D
D
DVoropaev2017-07-21 09:40:16
Arduino
DVoropaev, 2017-07-21 09:40:16

Why doesn't Serial.print(); work in header?

ec994124344d4faa85d02083eb523c01.png

In file included from protocol.ino:1:0:
/home/dproger/sketchbook/libraries/protocol/protocol.h: In function 'void send()':
/home/dproger/sketchbook/libraries/protocol/protocol.h :45:7: error: 'Serial' was not declared in this scope
Serial.print(comout[i]);
^
/home/dproger/sketchbook/libraries/protocol/protocol.h: In function 'int get(unsigned char&, unsigned char&, unsigned char&, unsigned int&)':
/home/dproger/sketchbook/libraries/protocol/protocol.h :49:8: error: 'Serial' was not declared in this scope
if (Serial.available())
^

// protocol.h (отрывок)
char comout[] = {0, 0, 0, 0, 0};
char comin[] = {0, 0, 0, 0, 0};
unsigned char bin[] = {1, 2, 4, 8, 16, 32, 64, 128};


void send(){
  for(int i = 0; i < 5; i++)
      Serial.print(comout[i]);
}

int get(unsigned char &d1, unsigned char &d2, unsigned char &d3, unsigned &d4){
   if (Serial.available()) 
  {
      char c2[] = {0, 0, 0, 0, 0};
      int i = 0;
      while (Serial.available() > 0)
      {
        char temp;
        temp = Serial.read();
        if(i < 5)
          c2[i] == temp;
      }
      if((i == 5) && (check(c2))){
      	for(int j = 0; i < 5; j++)
        	comin[j] = c2[j];
        d1 = comin[0];
        d2 = comin[1];
        d3 = comin[2];
        d4 = comin[3];
      	return 1;
    }else{
    	return -1;
    }
  } 
  return 0;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2017-07-21
@zagayevskiy

It doesn't "not work". In the same place, it is written in orange on black that Serial is not declared in this scope. That is, the compiler does not know what kind of entity it is. Looks like something is not connected.

V
vanyamba-electronics, 2017-07-25
@vanyamba-electronics

Add the line at the beginning of the sketch: This include must be above the "protocol.h" include.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question