Arduino Uno, SD card, random temp sensor (removed from code)
Absolute noob here. I spent a couple hours watching videos and trying to figure this out but I give up lol. It should be easy, right? So, below's my code. I thought it would be a boolean thing. The Tx LED flashes twice, and the red SD card module's LED flashes twice. I'm not sure what it's flashing for though: opening and closing the text file? opening/writing and closing?
Ideally, I want the LED to flash twice brightly to emulate the coolness factor of these onboard LEDs... but I was just trying to get it to turn on in the first place.
I also tried setting sdState = LOW, rather than to false, but that didn't work either.
Any help would be appreciated. Thank you!
#include <SPI.h>
#include <SD.h>
//Global Definitions
uint32_t timeStamp = 0;
//LED — for photoresistor, this will change
const int ledSD = 2;
bool sdState = false;
// DO NOT USE PIN 10
//SD Card
File myFile; //name of file object
const int cS = 4; //SD card write
void setup() {
Serial.begin(115200);
pinMode(ledSD, OUTPUT);
pinMode(10, OUTPUT); //Required for SD card module, do not use
//SD CARD
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(cS)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
//Print initial startup
myFile = SD.open("text.txt", FILE_WRITE);
if (myFile) {
myFile.println("");
myFile.close();
// debug
Serial.println("");
}
//debug
delay(500);
}
void loop() {
timeStamp = millis(); // this declaration must be in void loop
//LED
/* unsigned long ms = millis();
if ( (ms - preTime) >= 1000) {
preTime = ms;
*/
if (sdState == true){
digitalWrite(ledSD, HIGH);
} else {
digitalWrite(ledSD, LOW);
}
// SD CARD WRITE
myFile = SD.open("text.txt", FILE_WRITE);
if (myFile) {
sdState = true;
//Time
myFile.print(timeStamp);
Serial.print(timeStamp);
myFile.close();
sdState = false;
}
else {
Serial.println("error opening templog");
}
//END SD card write
delay(5000);
}