I am not a programmer!
I can't code effectively at all. They say programming is just like learning a new language and I was terrible at that as well. The way I think my brain works is if I can just touch it. Even in my mind's eye if I can physically manipulate the problem then I can figure it out. Code and math, they're intangible and for decades I've tried to learn and for decades I've been just a beginner. (Note: if i write a question mark in parenthesis (?) it's just my way of using a term that I don't fully understand the meaning of)
Problem
I need to draw numbers on the screen (speed, RPM, temperature, etc) but the function that does this only accepts const char variables and my data contains integers. How do I convert the integers into a string so the function can work?
The SmartMatrix3 Arduino library has a function to draw text on the screen on an "indexed layer". Not sure exactly what the "indexed" means yet but looking at the Layer_Indexed.h file in libraries I see the following:
void drawChar(int16_t x, int16_t y, uint8_t index, char character);
void drawString(int16_t x, int16_t y, uint8_t index, const char text []);
We have the drawChar and drawString functions. drawChar displays a single ASCII character and drawString a text string (which as I understand it is just an array of char). The const part makes the string read-only, and the brackets at the end denotes an array.
Solutions
I've tried a few times to simply convert a two-digit integer into a string, and then pass that string as a variable to the drawString function. I get an error message every time.
invalid conversion from 'char' to 'const char*' [-fpermissive]
Notice the asterisk at the end of that error? I think it has something to do with a pointer(?) and I know pointers are versatile but I still don't understand it yet.
What's Next?
Well, you know how you can bit-bang data on a microcontroller? That's pretty much how my programming works. I'll brute force a solution until I get something that works. It would probably be easier to just post it on a forum somewhere, but the answers I get from those smarter than I only serve to daze and confuse. Well, let's get on with it....
Current test code (04/29/2016 10:09:08)
#include <SmartMatrix3.h>
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 32; // known working: 32, 64, 96, 128
const uint8_t kMatrixHeight = 32; // known working: 16, 32, 48, 64
const uint8_t kRefreshDepth = 36; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE); // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kIndexedLayerOptions = (SM_INDEXED_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_INDEXED_LAYER(indexedLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kIndexedLayerOptions);
const int defaultBrightness = 100 * (255 / 100); // full brightness
//const int defaultBrightness = 15*(255/100); // dim: 15% brightness
const char speedValue = 20;
void setup() {
matrix.addLayer(&indexedLayer);
matrix.begin();
delay(3000);
}
void loop() {
indexedLayer.fillScreen(0);
indexedLayer.setFont(font8x13);
indexedLayer.setIndexedColor(1, { 255, 255, 255 });
indexedLayer.fillScreen(0);
indexedLayer.drawString(24, 8, 1,speedValue);
indexedLayer.swapBuffers(false);
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Dammit! Of course the moment I write up how confusing this is, I smack my forehead realizing the answer: Why am I using the drawString function to pass a char datatype? There is a drawChar function, duh. Compilation succeeded. See? Just needed to get out of my own head for a moment.
Are you sure? yes | no