将一个字符串分成一个数组
我的 Arduino 中有一串二进制数字。我需要将它们转换成数组。该数据代表 LED 显示屏中的光柱。在我的程序中,我已经有一个工作函数,它接受一个数组并使用数据在屏幕上显示单词。数据的格式需要如下所示:
我的字符串可能看起来有几种不同的方式。以下是示例:
char CurrentWord = "11111110001000000100011111110000000B00000001000001111111110000010000000";
或
char CurrentWord = "1111111 0001000 0001000 1111111 0000000 B0000000 1000001 1111111 1000001 0000000";
或什至:
char CurrentWord = "B1111111 B0001000 B0001000 B1111111 B0000000 B0000000 B1000001 B1111111 B1000001 B0000000";
上面的示例将在屏幕上生成单词“Hi”。然而,为了使显示正常工作,数据必须转换为数组。所以它必须看起来像这样:
int CurrentWordInt[] = {B1111111, B0001000, B0001000, B1111111, B0000000, B0000000, B1000001, B1111111, B1000001, B0000000};
我该怎么做?
I have a string of binary numbers coming into my Arduino. I need to convert them into an array. The data represents the columns of light in an LED display. In my program I already have a working function that takes an array and uses the data to display words to the screen. The data needs to be formatted like shown below:
My char string could look a few different ways. Here are the examples:
char CurrentWord = "11111110001000000100011111110000000B00000001000001111111110000010000000";
Or
char CurrentWord = "1111111 0001000 0001000 1111111 0000000 B0000000 1000001 1111111 1000001 0000000";
Or even:
char CurrentWord = "B1111111 B0001000 B0001000 B1111111 B0000000 B0000000 B1000001 B1111111 B1000001 B0000000";
The above examples would produce the word "Hi" on the screen. In order for the diplay to work however the data must be converted into an array. so it must look like this:
int CurrentWordInt[] = {B1111111, B0001000, B0001000, B1111111, B0000000, B0000000, B1000001, B1111111, B1000001, B0000000};
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果问题是如何让 C++ 解析二进制文件,那么使用这个宏:
Displays 127 8 8 127 0
请注意,该宏要求所有输入均为零,后跟七个一/零。
如果这不是您的问题,那么我不知道您想问我们什么。
If the question is how to make C++ parse binary, then use this macro:
Displays 127 8 8 127 0
Note that this macro requires all inputs to be a zero followed by seven ones/zeros.
If that isn't your question, then I don't know what you're asking of us.
从我在 如何阅读的答案中推断来自二进制文件的 bitN 整数数据?
请注意,这不会检查边界,并且会读取超出给定数组末尾的内容。
Extrapolated from my answer at How to read bitN integer data from a binary file?
Note this doesn't check boundries and will read past the end of the array given.
C++版本:
c++ version:
您可以使用类似这样的内容:
或
然后创建一个函数来翻译整个字符串...
建议:
使用“帧缓冲区”- 10 x 5 个字符或 10 个结构体的数组。
发送到 Arduino,正常,C 字符串。
根据需要从字符串转换字符,并将它们放入帧缓冲区中。通过这种方式,您可以非常轻松地创建滚动效果。
使用结构体来保存字符信息。
You can use something like this:
or
and then to make a function to translate a whole string...
Advice:
Use a "framebuffer" - an array of 10 x 5 chars or 10 structs.
Send to Arduino, normal, C strings.
Convert characters from string, as needed, and put them in the frame buffer. In this way you can create scroll effect, very easily.
Use a struct to keep character information.