【问题标题】:(Arduino) I want to create an array of uint8_t array(Arduino)我想创建一个 uint8_t 数组
【发布时间】:2017-08-30 09:43:49
【问题描述】:

我想在 uint8_t 中将 HEX 字符的关系硬编码存储为一个数组,例如在 php 中 a 会做类似的事情

$relation = [
    'uint8here-justasample',
    'uint8here-justasample',
    'uint8here-justasample',
    'uint8here-justasample',
    'uint8here-justasample'
];

如何在 Arduino 中做到这一点?

这是 uint8_t 数组,将存储在 uint8 的数组中

uint8_t event[8] = {'0','0','0','0','7','0','1','5'};

【问题讨论】:

  • 您想要一种将十六进制指定值存储在数组中的方法吗? {0x01, 0x02, ..., 0xFF}。单引号用于字符,而不是整数文字。
  • 是的,这就是我想要的,不知道该怎么做,我来自 php 世界。 @MitchellKline 最后我想要一个 uint8 来生成 CRC
  • 例如uint8_t 事件[3] = {0, 0x07, 0xA5}。请注意,不保证 uint8_t 由实现定义,但在 arduino 上使用可能没问题。

标签: c++ c arduino


【解决方案1】:

也许你想要的是:

uint8_t const event[][8] = 
{  {'0','0','0','0','7','0','1','5'}
,  {'0','0','0','0','7','0','1','5'}
,  {'0','0','0','0','7','0','1','5'}
};

【讨论】:

    【解决方案2】:

    那个“event[8]”数组中的值都是十进制的。

    unsigned char event[8] = {0, 0, 0, 7, 0, 1, 5};
    

    相当于 uint8_t。您可以使用以下方法打印此数组:

    for(int i; i<=sizeof(event); i++){
       Serial.print("0x");
       Serial.println(event[i], HEX);
    }
    

    您的 arduino 串行监视器将是: 0x0 0x0 0x0 0x7 0x0 0x1 0x5

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多