2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ArduinoUnoで16進変換して遊ぶ

Last updated at Posted at 2022-02-17

目的
 ライブラリを使わないで16進変換

o_con232.jpg

ちょっと違うが使用例

STM32G031のI2Cでマスターから送られた来たデータを受信する。(STM32G031J6M6)(Arduino)

ArduinoUNOを使い1から4096を文字列に変換 例intの1234を文字列の「1234」

バグ修正版




void setup() {

  Serial.begin(9600);

}

void loop() {

  char x = 0x12;

  char c_hex[] = {
    '0', '1', '2', '3', '4', '5', '6', '7',
    '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
  };

  char data_i[] = { c_hex[(x >> 4) & 0x0f], c_hex[x & 0x0f]  , 0 };

  Serial.println(data_i);
  delay(1000);

}





0から127まで 



void setup() {

  Serial.begin(9600);

}

void loop() {

  char x = 0x12;

  char c_hex[] = {
    '0', '1', '2', '3', '4', '5', '6', '7',
    '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
  };

  char data_i[] = { c_hex[x >> 4], c_hex[x & 0x0f]  , 0 };

  Serial.println(data_i);
  delay(1000);

}



2
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?