I have used an example project, and the file loads fine, but whenever I make the code, it stops working...
My code: (Not finished)
#include <SPI.h>
#include <SD.h>
#include <ArduinoJson.h>
const int inPin = 4;
const int outPin = 7;
File myFile;
JsonDocument doc;
void setup() {
//Setup input and output pins
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
Serial.begin(9600);
while (!Serial) {
; // Wait for serial port to connect
}
Serial.print("Initializing SD card...");
if (!SD.begin(2)) {
Serial.println("Initialization failed");
while (1);
}
Serial.println("Done");
myFile = SD.open("index.json", FILE_WRITE);
if (myFile) {
Serial.print("File opened successfully");
if (!myFile.available()) { //Check if file is empty or new
//Write default morse to index.json
char defaultMorse[] = "{\"A\":\".-\",\"B\":\"-...\",\"C\":\"-.-.\",\"D\":\"-..\",\"E\":\".\",\"F\":\"..-.\",\"G\":\"--.\",\"H\":\"....\",\"I\":\"..\",\"J\":\".---\",\"K\":\"-...\",\"L\":\".-..\",\"M\":\"--\",\"N\":\"-.\",\"O\":\"---\",\"P\":\".--.\",\"Q\":\"--.-\",\"R\":\".-.\",\"S\":\"...\",\"T\":\"-\",\"U\":\"..-\",\"V\":\"...-\",\"W\":\".--\",\"X\":\"-..-\",\"Y\":\"-.--\",\"Z\":\"--..\"}";
myFile.println(defaultMorse);
myFile.close();
} else {
Serial.print("File is not empty!");
}
} else {
myFile.close();
Serial.print("File failed to load");
Serial.println(myFile);
Serial.println(SD.open("index.json", FILE_WRITE));
}
}
void loop() {
//int inRead = digitalRead(inPin);
//int outWrite = inRead; //Temporary for later code
//digitalWrite(outPin, outWrite);
//Serial.print(outWrite);
}