DAAAANNKKKEEEEE ! ![]()
nun
wie kann ich dort noch eine fortlaufende nummerierung einbauen?
count +1 <- in dieser weise?
müsste das skript erst den vorwert aus der karte lesen und ihn dann +1 schreiben oder?!
Nun der funktionierende Code ohne Counter: (für die es auch haben wollen...)
#include <SD.h>
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(4, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("Karte Eingelegt");
}
void loop()
{
//***************************************************
// Liest den Analog Eingang auf Pin.
int Spannung1 = analogRead(A0);
int Spannung2 = analogRead(A1);
int Spannung3 = analogRead(A2);
int Spannung4 = analogRead(A3);
// Konvertiert das Signal (geht von 0 - 1023) zu einer Spannung (0 - 20V):
float Volt1 = Spannung1 * (33.9 / 1023.0);
float Volt2 = Spannung2 * (33.9 / 1023.0);
float Volt3 = Spannung3 * (33.9 / 1023.0);
float Volt4 = Spannung3 * (33.9 / 1023.0);
//***************************************************
// make a string for assembling the data to log:
String dataString = "";
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print(Volt1);
dataFile.println(" Volt");
//dataFile.println(Volt2);
//dataFile.println(" Volt");
//dataFile.println(Volt3);
//dataFile.println(" Volt");
//dataFile.println(Volt4);
//dataFile.println(" Volt");
dataFile.close();
// print to the serial port too:
Serial.print(Volt1);
Serial.println(" Volt");
//Serial.print(Volt2);
//Serial.println(" Volt");
//Serial.print(Volt3);
//Serial.println(" Volt");
//Serial.print(Volt4);
//Serial.println(" Volt");
delay (1000);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
DAAANNKKEEE