Last active
June 11, 2017 02:44
-
-
Save jdieg0/ccaf4cc5991088503259a36d53aa3312 to your computer and use it in GitHub Desktop.
Zufallswerte mit Zeitstempel auf SD-Karte des Wemos D1 Mini schreiben.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SD.h> | |
const int CS = D8; | |
const char FILENAME[] = "RANDOM.TXT"; | |
unsigned long time; | |
int randNumber; | |
File myFile; | |
void setup() { | |
Serial.begin(9600); | |
// Zufallsgenerator initialisieren mit dem Rauschen des Analog-Eingangs | |
randomSeed(analogRead(A0)); | |
// SD-Karte initialisieren | |
Serial.print("\r\nInitialisiere SD-Karte..."); | |
pinMode(CS, OUTPUT); | |
if (!SD.begin(CS)) { | |
Serial.println(" fehlgeschlagen!"); | |
return; | |
} | |
Serial.println(" fertig."); | |
} | |
void loop() { | |
// Zeit seit Start des Programms in ms ermitteln | |
time = millis(); | |
// Zufallszahl generieren | |
randNumber = random(1024); | |
// Werte auf SD-Karte schreiben | |
Serial.print("Schreibe in "); | |
Serial.print(FILENAME); | |
Serial.print("..."); | |
myFile = SD.open(FILENAME, FILE_WRITE); | |
if (myFile) { | |
myFile.print(time); | |
// Tabulator als Trennzeichen | |
myFile.print("\t"); | |
myFile.println(randNumber); | |
myFile.close(); | |
Serial.println(" fertig."); | |
} | |
else { | |
Serial.println(" fehlgeschlagen."); | |
} | |
// 1 s warten bis zum nächsten Wertepaar | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment