0

5 つの変数を読み取り、それらをシリアル ポートを介して Bluetooth レシーバーに送信するライブラリを作成しようとしています。多くのエラーが発生し、どこに行けばよいかわかりません。ポインターを実装する必要がありますか?

これがArduinoコードです....

#include <serialComms.h>
serialComms testing;

void setup()
{
 Serial.begin(9600); 
}
char data[] = {1,2,3,4,5,6};

void loop()
{

 for(int t = 0;t<6;t++)
 {
  data[t] = data[t]++; 
 }
  testing.updateUser(data);
  delay(250);

}

serialComms.cpp

#include <Arduino.h>
#include <serialComms.h>

void serialComms::init()
{
  // This is where the constructor would be...right now we are too stupid to have one
}

void serialComms::readAllBytes()  // Target Pin,Values
{
}
 void serialComms::assignBytes()
{
  for(int t  = 0;t<5;t++)
  {
    digitalWrite(12,HIGH);
    delay(250);
    digitalWrite(12,LOW);
  }   
}
void serialComms::updateUser(char t[])
{
    Serial.write(t,5);
}

serialComms.h

#ifndef serialComms_h
#define serialComms_h
/* serialComms Class */
class serialComms
{
  public:
       serialComms() {};
void init();
void readAllBytes(); // Will be used to create the array --> two variables for now...
void assignBytes();
void updateUser(char t[]);
    };
#endif

ここに私が得ているエラーがあります...

- 
- serialComms.cpp:28: error: invalid conversion from 'char*' to 'const uint8_t*'
- serialComms.cpp: In member function 'void serialComms::updateUser(char*)':
- serialComms.cpp:27: error: expected primary-expression before ']' token
4

2 に答える 2

1

Serial.writeは、次のような定数文字列のみを送信できます。

Serial.write(“hello”);

そのため、エラーエラー:「char*」から「constuint8_t*」への無効な変換

使用

char temp[max_length];
sprintf(temp,"%s",t);
Serial.write(temp);
于 2013-03-12T10:33:13.253 に答える
1

例:

    void setup()
{

  Serial.begin(9600);
  char string_array[] = "hello";
  char data_array[] = {1,2,3,4,5,6};
  unsigned char data_array_uchar[] = {21,22,23,24,25,26};
  uint8_t uint8_array[] = {11,12,13,14,15,16};
  char alpha_array[] = {0x41,0x42,0x43,0x44,0x45,0x46};
  // take note that sizeof() is a precompile command... number of places/size of each place.

  updateUserPrint(string_array);
  updateUserWrite(data_array, sizeof(string_array));
  updateUserWriteUchar(data_array_uchar, sizeof(data_array_uchar));
  updateUserWriteUchar(uint8_array, sizeof(uint8_array));
  updateUserWriteUint(uint8_array, sizeof(string_array));
  updateUserAlpha(alpha_array, sizeof(string_array));
}
void updateUserPrint(char *s)
{  //note a string aka array of char's is ended with a null.
  Serial.print(s); // this can detect.
  Serial.println();
}
void updateUserWrite(char *t, size_t len)
{  //note an array of int's is not ended with a null. so you need to know how long it is.
  for (int n = 0; n < len ; n++) {
    Serial.print(t[n],DEC);
    Serial.print(",");
  }
  Serial.println();
}
void updateUserWriteUchar(unsigned char *t, size_t len)
{  //note an array of int's is not ended with a null. so you need to know how long it is.
  for (int n = 0; n < len ; n++) {
    Serial.print(t[n],DEC);
    Serial.print(",");
  }
  Serial.println();
}
void updateUserWriteUint(uint8_t *t, size_t len)
{  //note an array of int's is not ended with a null. so you need to know how long it is.
  for (int n = 0; n < len ; n++) {
    Serial.print(t[n],DEC);
    Serial.print(",");
  }
  Serial.println();
}
void updateUserAlpha(char *t, int len)
{  //note an array of int's is not ended with a null. so you need to know how long it is.
  for (int n = 0; n < len ; n++) {
    Serial.write(t[n]);
  }
  Serial.println();
}  

以下を生成します。

hello
1,2,3,4,5,6,
21,22,23,24,25,26,
11,12,13,14,15,16,
11,12,13,14,15,16,
ABCDEF
于 2013-03-12T13:22:35.080 に答える