Advertisement
dianartanto

dataloggermodifikasi

Jun 22nd, 2015
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <SD.h>
  3. const int chipSelect = 10;
  4. void setup(){
  5.   Serial.begin(9600);
  6.   pinMode(10, OUTPUT);
  7.   if (!SD.begin(chipSelect)) {
  8.     Serial.println("kartu memori error");}}
  9. void loop(){
  10.   String dataString = "";
  11.   for (int analogPin = 0; analogPin < 3; analogPin++) {
  12.     int sensor = analogRead(analogPin);
  13.     dataString += String(sensor);
  14.     if (analogPin < 2) {
  15.       dataString += ",";}}
  16.   File dataFile = SD.open("datalog.txt", FILE_WRITE);
  17.   if (dataFile) {
  18.     dataFile.println(dataString);
  19.     dataFile.close();
  20.     Serial.println(dataString);}  
  21.   else {
  22.     Serial.println("file datalog.txt error");}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement