fork download
  1. byte incomingByte;// 用來儲存收進來的 data byte
  2. byte receive[12];//byte陣列 裡面儲存接收到的資料
  3. boolean newLineReceived = false;// 是否已收到換行字元
  4. void setup()
  5. {
  6. Serial.begin(9600);//Mega2560監控鮑率
  7. Serial1.begin(2400);//與傳送板子溝通鮑率
  8. }
  9. void loop()
  10. {
  11. //將得到的陣列值印出
  12. for(int i=0;i<2;i+1)
  13. {
  14. Serial.print("current1:");
  15. Serial.print(receive[i]);
  16. Serial.println(receive[i+1]);
  17. }
  18. for(int j=2;j<4;j+1)
  19. {
  20. Serial.print("current2:");
  21. Serial.print(receive[j]);
  22. Serial.println(receive[j+1]);
  23. }
  24. for(int k=4;k<6;k+1)
  25. {
  26. Serial.print("temperature1:");
  27. Serial.print(receive[k]);
  28. Serial.println(receive[k+1]);
  29. }
  30. for(int l=6;l<8;l+1)
  31. {
  32. Serial.print("temperature2:");
  33. Serial.print(receive[l]);
  34. Serial.println(receive[l+1]);
  35. }
  36. for(int m=8;m<10;m+1)
  37. {
  38. Serial.print("voltage1:");
  39. Serial.print(receive[m]);
  40. Serial.println(receive[m+1]);
  41. }
  42. for(int n=10;n<12;n+1)
  43. {
  44. Serial.print("voltage2:");
  45. Serial.print(receive[n]);
  46. Serial.println(receive[n+1]);
  47. }
  48. }
  49. void serialEvent()
  50. {
  51. while (Serial1.available())//是否有傳值進入
  52. {
  53. incomingByte = Serial1.read();// 把讀取的值 放在incomingByte
  54. for(int o=0;o<12;o++)
  55. {
  56. receive[o] += incomingByte;//將資料存入receive陣列
  57. }
  58. if (incomingByte == '\n')//以換行字元得知是否收到完整封包
  59. {
  60. newLineReceived = true;
  61. }
  62. }
  63. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:1: error: unknown type name ‘byte’
 byte incomingByte;// 用來儲存收進來的 data byte
 ^~~~
prog.c:2:1: error: unknown type name ‘byte’
 byte receive[12];//byte陣列 裡面儲存接收到的資料
 ^~~~
prog.c:3:1: error: unknown type name ‘boolean’
 boolean newLineReceived = false;// 是否已收到換行字元
 ^~~~~~~
prog.c:3:27: error: ‘false’ undeclared here (not in a function)
 boolean newLineReceived = false;// 是否已收到換行字元
                           ^~~~~
prog.c: In function ‘setup’:
prog.c:6:1: error: ‘Serial’ undeclared (first use in this function)
 Serial.begin(9600);//Mega2560監控鮑率
 ^~~~~~
prog.c:6:1: note: each undeclared identifier is reported only once for each function it appears in
prog.c:7:1: error: ‘Serial1’ undeclared (first use in this function)
 Serial1.begin(2400);//與傳送板子溝通鮑率
 ^~~~~~~
prog.c: In function ‘loop’:
prog.c:12:20: warning: statement with no effect [-Wunused-value]
   for(int i=0;i<2;i+1)
                   ~^~
prog.c:14:4: error: ‘Serial’ undeclared (first use in this function)
    Serial.print("current1:");
    ^~~~~~
prog.c:18:19: warning: statement with no effect [-Wunused-value]
  for(int j=2;j<4;j+1)
                  ~^~
prog.c:24:19: warning: statement with no effect [-Wunused-value]
  for(int k=4;k<6;k+1)
                  ~^~
prog.c:30:19: warning: statement with no effect [-Wunused-value]
  for(int l=6;l<8;l+1)
                  ~^~
prog.c:36:20: warning: statement with no effect [-Wunused-value]
  for(int m=8;m<10;m+1)
                   ~^~
prog.c:42:21: warning: statement with no effect [-Wunused-value]
  for(int n=10;n<12;n+1)
                    ~^~
prog.c: In function ‘serialEvent’:
prog.c:51:10: error: ‘Serial1’ undeclared (first use in this function)
   while (Serial1.available())//是否有傳值進入
          ^~~~~~~
prog.c:60:27: error: ‘true’ undeclared (first use in this function)
         newLineReceived = true;
                           ^~~~
stdout
Standard output is empty