我是 C 的新手,在嘗試將我的存盤next_frame在變數中時遇到問題。任何幫助都會很棒,因為我認為這可能是我所缺少的簡單東西。
如果我只是更改以下內容,它就可以正常作業,只有當我嘗試將其存盤next_frame在變數中時,它才會編譯。
// Doesn't compile
oled_write_raw_P(next_frame, FRAME_SIZE);
// Compiles
oled_write_raw_P(frames[abs((FRAME_COUNT - 1) - current_frame)];, FRAME_SIZE);
完整代碼
#define FRAME_COUNT 5 // Animation Frames
#define FRAME_SIZE 256
#define FRAME_DURATION 200 // MS duration of each frame
// Variables
uint32_t timer = 0;
uint8_t current_frame = 0;
char next_frame;
static void render_animation(void) {
static const char PROGMEM frames[FRAME_COUNT][FRAME_SIZE] = {
// Images here, removed for example
};
// If timer is more than 200ms, animate
if (timer_elapsed32(timer) > FRAME_DURATION) {
timer = timer_read32();
current_frame = (current_frame 1) % FRAME_COUNT;
next_frame = frames[abs((FRAME_COUNT - 1) - current_frame)];
// Set cursor position
oled_set_cursor(128, 0);
// Write next frame
oled_write_raw_P(next_frame, FRAME_SIZE);
}
}
這些是錯誤:
錯誤:從 'const char *' 賦值給 'char' 從指標生成整數而不進行強制轉換 [-Werror=int-conversion] next_frame = frames[abs((FRAME_COUNT - 1) - current_frame)];
錯誤:傳遞“oled_write_raw_P”的引數 1 使指標來自整數而不進行強制轉換 [-Werror=int-conversion] oled_write_raw_P(next_frame, FRAME_SIZE);
uj5u.com熱心網友回復:
線
next_frame = frames[abs((FRAME_COUNT - 1) - current_frame)]
沒有意義。
您要為其賦值的變數next_frame的型別為char。但是,您正在為其分配運算式
frames[abs((FRAME_COUNT - 1) - current_frame)]
它衰減為指向子陣列第一個元素的指標,因此運算式的計算結果為 type 的值const char *。
我不太確定你想要完成什么,但我想你的問題的解決方案是將 to 的型別更改next_frame為const char *,以便型別匹配。為此,您可以更改行
char next_frame;
至:
const char *next_frame;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/536618.html
標籤:Cqmkqmk固件
