2013-04-18 3 views
0

여기에 게시물의 후속 조치입니다 - Writting data to the Arduino's onboard EEPROM URL의 스 니펫을 사용해 보았지만 작동하지 않습니다. 아래 오류를 해결하는 데 도움주세요. 여기 Arduino EEPROM에 데이터 작성하기

write_to_eeprom.cpp:8:5: error: expected unqualified-id before '[' token 
write_to_eeprom.cpp: In function 'void setup()': 
write_to_eeprom.cpp:12:16: error: 'stringToWrite' was not declared in this scope 
write_to_eeprom.cpp: In function 'void loop()': 
write_to_eeprom.cpp:22:33: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'char*' [-fpermissive] 
write_to_eeprom.cpp: In function 'void EEPROM_write(void*, byte)': 
write_to_eeprom.cpp:32:32: error: 'void*' is not a pointer-to-object type 

#include <EEPROM.h> 
#include <LiquidCrystal.h> 
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7); 
char[] stringToWrite = "Test"; 
void setup() { 
    lcd.begin(16, 2); 
    delay(5000); 
    EEPROM_write(stringToWrite, strlen(stringToWrite)); 
} 

void loop() { 
    delay(10000); 
    int addr = 0; 
    byte datasize = EEPROM.read(addr++); 
    char stringToRead[0x20];   // allocate enough space for the string here! 
    char * readLoc = stringToRead; 
    for (int i=0;i<datasize; i++) { 
    readLoc = EEPROM.read(addr++); 
    readLoc++; 
    } 
} 
// Function takes a void pointer to data, and how much to write (no other way to know) 
// Could also take a starting address, and return the size of the reach chunk, to be more generic 
void EEPROM_write(void * data, byte datasize) { 
    int addr = 0; 
    EEPROM.write(addr++, datasize); 
    for (int i=0; i<datasize; i++) { 
    EEPROM.write(addr++, data[i]); 
    } 
} 

답변

0

글쎄, 당신은 당신의 코드를 수정해야하는 코드입니다 :

라인 (8) [-] stringToWrite 라인 (12) 후에 갈 필요 - 더 얻어야한다 8 행을 수정 한 후

행 22 - readLoc을 참조 해제해야합니다. 앞에 '*'를 추가하십시오.

line 32 - 매개 변수 "data"는 크기가없는 void에 대한 포인터입니다. 따라서 배열로 사용할 수 없습니다.

무효 EEPROM_write (문자 * 데이터 바이트 datasize) 컴파일러 오류를 해결

: 당신은 선언을 변경할 수 있습니다. 코드의 의미를 간략하게 살펴보면 원하는대로 할 수 있습니다. 행운을 빕니다.