how to make data in sd card be a input again

pls help me in my problem in programming codes, it goes this way, i have already a data in my sd card i want it to be a input again, im thinking the code like this:

void set(){

myFile = SD.open("test.txt");

      temp=myFile.read();

      Serial.print(temp);

    myFile.close();


}
void loop(){

}

i find it doesn't have error, my problem is the output is -1, which in my data in my card is 59.
im little confused :confused:

and the way this forum really help me alot in my project. :slight_smile:

epic2big:
i find it doesn't have error

Error, undefined reference to setup...

oh…heheheh…ty…but pls help me in my problem…except for that set up…i just type it direct…hehehh…

hehehehehe why don't you copy the actual code. When I see a miscopy like that I assume that there may be more. You'd be amazed how many people retype their code here and fix the mistake when they copy it and then don't understand when we say there's nothing wrong.

You should also include any relevant details about this SD card file. As it sits you're getting a -1 which is what read would return if the file was empty.

if i post the code, it to long…is improper post it.

epic2big:
if i post the code, it to long..is improper post it.

Oh, so you already know where in your code the error is? You must if you know what part i need to see to find it. If you already know then why are you asking here?

If you don't know then you're kind of stuck. The code you posted doesn't compile. I doubt it would produce the output you describe unless your text file is empty. So you've made some mistake somewhere else. If you're not going to show us the code, then there isn't a snowball's chance in hell that anyone here will be able to spot the mistake.

We're programmers. Believe it or not, we can handle long code. What we can't do is look at your little snippet and figure out what stupid thing you did somewhere else in your code.

oh ok…i about that i mean no harm…im sorry… :o

// Coin to Bill System

#include <Servo.h>

Servo myservo;

// constants
const int coinpin = 20,ledpin = 13,button1 = 19;
int servoPin = 22,buttonState =0; 

// Variables
volatile int pulse = 0,a=0;
Servo Servo1; 
boolean bInserted = false;
boolean  b=0,c=0;


//...
// Inventory Systems
#include <SD.h>
#include <SPI.h>

#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)

#define redLED 10 //define the LED pins
#define greenLED 11

char* password ="1234"; //create a password
int pozisyon = 0; //keypad position

int convert_integer2,convert_integer1;

File myData1;
File myData2;


const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;

char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad

  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins [rows] = {2, 3, 4, 5}; //pins of the keypad
byte colPins [cols] = {6, 7, 8, 9};

Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);

LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7)


void setup(){
  
//Coin to Bill System

 Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
  pinMode(ledpin, OUTPUT);
  Servo1.attach(servoPin);
  pinMode(button1,INPUT);
  
  // Inventory Systems
  lcd.begin(16, 2);
  pinMode(redLED, OUTPUT);  //set the LED as an output
  pinMode(greenLED, OUTPUT);
  setLocked (true); //state of the password
  
 if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
    
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }

 inventory();
 
}


void loop(){
//Coin to Bill System
 myservoloop();
 checkButton1();
 checkcoin();
 

// Inventory Systems
  char whichKey = myKeypad.getKey(); //define which key is pressed with getKey
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("    Welcome");
  lcd.setCursor(0, 1);
  lcd.print(" Enter Password");

  if(whichKey == '*' || whichKey == 'A' ||       //define invalid keys
  whichKey == 'B' || whichKey == 'C' || whichKey == 'D'|| whichKey == '#'|| whichKey == '*'){

    pozisyon=0;
    setLocked (true);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("TRY AGAIN!");
    delay(1000);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("To Logout");
    lcd.setCursor(0,1);
    lcd.print("Press Again"); 
    delay(1000);
    lcd.clear();
  }
  if(whichKey == password [pozisyon]){

    pozisyon ++;
  }
  if(pozisyon == 4){ 
    
    setLocked (false);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*** Verified ***");
    delay(3000);
    lcd.clear();
    systemfunction();

  }
  delay(100);
}

void inventory(){ // this is where my problem.

  myData1 = SD.open("C-B.text");
  
    Serial.print(myData1.read()); 


myData1.close();


  
}
void deleting1(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Do you wish to");
  lcd.setCursor(0,1);
  lcd.print("delete the data?");
  delay(2000);
  lcd.clear();
  lcd.print("Yes['#'] NO['*']");
  
 char deletingkey = myKeypad.waitForKey();
 
  if(deletingkey =='#'){
    Serial.println("Removing C-B.text");
    SD.remove("C-B.txt");
    if(SD.exists("C-B.txt")){
      Serial.println("The C-B exist");
    }else{
      Serial.println("File has successfully remove");
      return;
    }
    if(deletingkey == '*'){
      return;
    }
  }
}

void deleting2(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Do you wish to");
  lcd.setCursor(0,1);
  lcd.print("delete the data?");
  delay(2000);
  lcd.clear();
  lcd.print("Yes['#'] NO['*']");
  
 char deletingkey = myKeypad.waitForKey();
 
  if(deletingkey =='#'){
    Serial.println("Removing C-B.text");
    SD.remove("B-C.txt");
    if(SD.exists("B-C.txt")){
      Serial.println("The B-C exist");
    }else{
      Serial.println("File has successfully remove");
      return;
    }
    if(deletingkey == '*'){
      return;
    }
  }
}
void systemfunction(){
  
   lcd.setCursor(0,0);
 lcd.print("Pls Enter your");
  lcd.setCursor(0,1);
  lcd.print("options:");
  delay(1000);
  lcd.setCursor(0,0);
  lcd.print ("Bill to coins[1]");
  lcd.setCursor(0,1);
  lcd.print ("Coins to Bill[2]");
  delay(1000);
  lcd.clear();
  
char whichKey = myKeypad.waitForKey();

 if(whichKey == '1'){// coin to bill system
  lcd.setCursor(0,0);
  lcd.print("Pls Enter Number");
  lcd.setCursor(0,1);
  lcd.print("of Coins:");
  

char coins;
String convert1;

while(coins !='#'){

coins = myKeypad.waitForKey();

if(coins =='#'){

   // Create/Open file 
  myData1 = SD.open("C-B.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  
  if (myData1) {
    
    // Write to file
    myData1.println(convert_integer1);
    myData1.close(); // close the file
    Serial.println("Your data has successfully saved");
  }
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening C-B.txt");
  }
  
// Reading the file
 myData1 = SD.open("C-B.txt");
 if(myData1){

  Serial.println("Reading:");
  //reading whole file
  while(myData1.available()){
    Serial.write(myData1.read());
  }
  myData1.close();
 }
 
 deleting1();

   
}

if(coins =='*'){
  return 0;
}

if(coins =='1'||coins =='2'||coins =='3'||coins =='4'||coins =='5'||coins =='6'||
 coins =='7'||coins =='8'||coins =='9'){

  convert1=String(convert1 + coins);

convert_integer1 = convert1.toInt();


 }
   lcd.print(coins);
}
 }

 
 
 else if(whichKey == '2'){ //bill to coins system

   char bills;
  String convert2;

  lcd.setCursor(0,0);
  lcd.print("Pls Enter Number");
  lcd.setCursor(0,1);
  lcd.print("of Bills:");
  
   while(bills !='#'){
    bills = myKeypad.waitForKey();
    
    
if(bills =='#'){

   // Create/Open file 
  myData2 = SD.open("B-C.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  
  if (myData2) {
    
    // Write to file
    myData2.println(convert_integer2);
    myData2.close(); // close the file
    Serial.println("Your data has successfully saved");
  }
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening B-C.txt");
  }
  
// Reading the file
 myData2 = SD.open("B-C.txt");
 if(myData2){

  Serial.println("Reading:");
  //reading whole file
  while(myData2.available()){
    Serial.write(myData2.read());
  }
  myData2.close();
 }
  
 deleting2();
  
}
    lcd.print(bills);

   if(bills =='1'||bills =='2'||bills =='3'||bills =='4'||bills =='5'||bills =='6'||
 bills =='7'||bills =='8'||bills=='9'){

  convert2=String(convert2 + bills);

convert_integer2 = convert2.toInt();
 }

    
   }
   
 }
  else{
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Invalid Key!");
    delay(1000);
    lcd.clear();
     return systemfunction();
  }


    
  
}



void setLocked(int locked){
  if(locked){
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
    }
    else{
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, HIGH);
    }
  }
//...
// Coin to Bill System

void checkcoin(){


   if( bInserted  ){ // for show LED ON when Inserted
     bInserted = false;
     digitalWrite(ledpin, HIGH);    
     delay(1000);
  
  }else{
   
  // Turn off LED
  digitalWrite(ledpin, LOW);
  }
  
}
void checkButton1() {

  buttonState = digitalRead(button1);

}

// Interrupt
void coinInterrupt(){
 
  // Each time a pulse is sent from the coin acceptor,
  // interrupt main loop to add 1  and flip on the LED
  pulse++ ;
  a++;
  bInserted = true;

 digitalWrite(ledpin, HIGH);
 Serial.println( pulse );

   
}

void myservoloop(){

if(a >= 4 && buttonState == HIGH && convert_integer1 > 19 || convert_integer2 >19 ){
  
  Servo1.write(0);
  delay(1000);

 Servo1.write(90);
 delay(1000);

  a=(a-4);

merging();
}


   if( bInserted  ){ // for show LED ON when Inserted
     bInserted = false;
     digitalWrite(ledpin, HIGH);    
     delay(1000);
     
     
  }else{
   
  // Turn off LED
  digitalWrite(ledpin, LOW);

}

}
//...
// merging system codes
void merging(){
  
}
const int coinpin = 20,ledpin = 13,button1 = 19;

So, you have a coin pin, an LED pin, and a button one. WTF is a button one?

void inventory(){ // this is where my problem.

  myData1 = SD.open("C-B.text");
  
    Serial.print(myData1.read());


myData1.close();


  
}

The ONLY excuse for putting the { on the same line as the function is to save real estate. You look really stupid then following that by a sh*tload of blank lines.

ThereisNOexcusefornotusingatleastonespacetoseparatethecurlybracefromthefunctionstatement.

Now, where is the PROOF that there is anything in the file?

The read() method returns an int, so that it can tell you that there was nothing to read. The print() method does NOT print the int as a character, if there was data to read.

You should NOT be calling print() with the output of read(), without the use of an intermediate variable of the correct type (or a cast, if you KNOW what you are doing. (You clearly don't, so do not go there.)