Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: help my program please on: July 03, 2012, 10:49:38 pm
this is my whole code.

Code:
#include <SD.h>
#include <LiquidCrystal.h>

int CS_pin = 53;

volatile long lastSave = 0;
volatile long lcdTimeOut = 0;
volatile int saveInterval = 10;
volatile int lcdInterval= 60;
const int reps = 9;

LiquidCrystal lcd(8,3,4,5,6,7);

 
#define muxA0 15
#define muxA1 16
#define muxA2 17
#define tempPin 0
#define lcdLight 9
#define button1 2                  
int button1INT = 0;
                    

#define aref_voltage 1.1


const int chs = 8;
const int numReadings = 10;
long tempInArray[numReadings][chs];
int index = 0;
long total[chs];
float averages[chs];

void error(char *str)
{
  lcd.clear();
  lcd.home();
  lcd.print("error: ");
  lcd.print(str);
  while(1);
}

void setup(void)
{
 
  analogReference(INTERNAL1V1);
                      
  pinMode(muxA2, OUTPUT);
  pinMode(muxA1, OUTPUT);
  pinMode(muxA0, OUTPUT);
  pinMode(button1, INPUT);
  digitalWrite(lcdLight, HIGH);
  lcd.begin(20,4);  
  lcd.setCursor(0,0);
  lcd.print("Tugas Akhir");
  lcd.setCursor(0,1);
  lcd.print("Miniatur Hujan Salju");
  delay (5000);
  lcd.clear();
  
  lcd.setCursor(0,0);
  lcd.print ("Oleh: ");
  lcd.setCursor(0,1);
  lcd.print ("Mochamad Rikki Firmansyah");
  lcd.setCursor(0,2);
  lcd.print ("dan");
  lcd.setCursor(0,3);
  lcd.print ("Ichsan T Primanizar");
  delay (5000);
  lcd.clear();

  //initialize the SD card
  if (!SD.begin(CS_pin))
    {
      lcd.setCursor(0,0);
      lcd.println ("Card Failure ");
      delay (3000);
      lcd.clear();
      return;
    }
      lcd.println ("Card Ready");
      delay (3000);
      lcd.clear();
      
  
  File commandFile = SD.open ("COMMAND.txt");
  if (commandFile)
  {
    lcd.setCursor(0,0);
    lcd.println ("Membaca File");
    delay (3000);
    lcd.clear();
    while (commandFile.available());
  }
  else
  {
    lcd.println ("File Tdk Trsedia");
    delay (3000);
    lcd.clear();
  }
  
  
  File logFile = SD.open ("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println (", , , , , , , ,");
    String header = "Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8";
    logFile.println (header);
    logFile.close();
  }
  else
  {
    lcd.setCursor (0,0);
    lcd.print  ("data failed");
    delay (2000);
    lcd.clear();
  }


  saveInterval = saveInt(); //call saveInt sub-function and return value
  lcdInterval = lcdInt();   //call lcdInt sub-function and return value


  for (int channel = 0; channel < chs; channel++) {
    for (int i = 0; i < numReadings; i++) {
      tempInArray[i][channel] = 0; //initialize all values to 0
    }
  }
}
 


void loop(void)
{
  
  for (int channel = 0; channel < chs; channel++) {
    total[channel] = total[channel] - tempInArray[index][channel];
  }
  

    for (int channel = 0; channel < chs; channel++) {
    
      digitalWrite(muxA0, (channel & 1));
      digitalWrite(muxA1, (channel & 2)>>1);
      digitalWrite(muxA2, (channel & 4)>>2);  
      delay(5);
      
    
      analogRead(tempPin);
      delay(20);
      tempInArray[index][channel] = analogRead(tempPin);    
        
  }
  for (int channel = 0; channel < chs; channel++) {
    total[channel] = total[channel] + tempInArray[index][channel];
    averages[channel] = total[channel] / numReadings;
    averages[channel] = averages[channel] * aref_voltage / 1024;
    averages[channel] = averages[channel] * 100;
  }
    
  index = index++;
  if (index >= numReadings) {
    index = 0;
  }

  delay(500);  
              
  lcd.home();
  int row = 0;
  for (int i = 0; i <=6; i = i + 2) {
    lcd.setCursor(0,row);
    lcd.print("Ch");
    lcd.print(i+1);
    lcd.print(":");
  lcdPrintDouble(averages[i],1);
    lcd.setCursor(10,row);
    lcd.print("Ch");
    lcd.print(i+2);
    lcd.print(":");  
   lcdPrintDouble(averages[i+1],1);  
    row++; //increment row counter
  }

int saveInt() {
  int buttonValue1;
  int buttonValue2;
  int buttonState;
  int minutes;

  lcd.clear();
  lcd.print("Choose save interval");
  delay(500);
  lcd.setCursor(0,1);
  lcd.print(saveInterval);
  lcd.setCursor(3,1);
  lcd.print("seconds");
  buttonState = digitalRead(button1);
  
  
    buttonValue1 = digitalRead(button1);
    delay(10);
    buttonValue2 = digitalRead(button1);
    if (buttonValue1 == buttonValue2) {
      if (buttonValue1 != buttonState) {
        if (buttonValue1 == LOW) {
          if (saveInterval >= 5 && saveInterval < 20) {
            saveInterval = saveInterval + 5; //set value to 5, 10, 15 or 20 seconds
          } else if(saveInterval >= 20 && saveInterval < 30) {
            saveInterval = saveInterval + 10; //set value to 30 seconds
          } else if(saveInterval >= 30 && saveInterval < 60) {
            saveInterval = saveInterval + 30; //set value to 60 seconds
          } else if(saveInterval >= 60 && saveInterval < 120) {
            saveInterval = saveInterval + 60; //set value to 120 seconds
          } else if(saveInterval >= 120 && saveInterval < 300) {
            saveInterval = saveInterval + 180; //set value to 5 minutes (300 seconds)
          } else if(saveInterval >= 300 && saveInterval < 600) {
            saveInterval = saveInterval + 300; //set value to 10 minutes (600 seconds)
          } else if(saveInterval >= 600) {
            saveInterval = 5;
          }
        
          lcd.setCursor(0,1);
          lcd.print("   ");
          if (saveInterval <= 60) {
            lcd.setCursor(0,1);
            lcd.print(saveInterval);
            lcd.setCursor(3,1);
            lcd.print("seconds");
          } else if(saveInterval > 60) {
            minutes = saveInterval / 60;
            lcd.setCursor(0,1);
            lcd.print(minutes);
            lcd.setCursor(3,1);
            lcd.print("minutes");
          }
  
        }
      }
      buttonState = buttonValue1;
                                
    }

 }
  lcd.setCursor(0,3);
  lcd.print("Storing");
  delay(400);
  for (int i = 0; i <= 2; i++) {
    lcd.print(".");
    delay(350);
  }
  return saveInterval;
}

int lcdInt() {
  int buttonValue1;
  int buttonValue2;
  int buttonState;
  int minutes;
  lcd.clear();
  lcd.print("Choose LCD backlight");
  lcd.setCursor(0,1);
  lcd.print("timeout:");
  delay(500);
  lcd.setCursor(0,2);
  lcd.print(lcdInterval);
  lcd.setCursor(3,2);
  lcd.print("seconds");
  buttonState = digitalRead(button1);
 
  {
    buttonValue1 = digitalRead(button1);
    delay(10);
    buttonValue2 = digitalRead(button1);
    if (buttonValue1 == buttonValue2) {
      if (buttonValue1 != buttonState) {
        if (buttonValue1 == LOW) {
          if(lcdInterval >= 10 && lcdInterval < 30) {
            lcdInterval = lcdInterval + 10;
          } else if(lcdInterval >= 30 && lcdInterval < 60) {
            lcdInterval = lcdInterval + 30;
          } else if(lcdInterval >= 60 && lcdInterval < 120) {
            lcdInterval = lcdInterval + 60;
          } else if(lcdInterval >= 120 && lcdInterval < 300) {
            lcdInterval = lcdInterval + 180;
          } else if(lcdInterval >= 300 && lcdInterval < 600) {
            lcdInterval = lcdInterval + 300;
          } else if(lcdInterval >= 600) {
            lcdInterval = 10;
          }
        
          lcd.setCursor(0,2);
          lcd.print("   ");
          if (lcdInterval <= 60) {
            lcd.setCursor(0,2);
            lcd.print(lcdInterval);
            lcd.setCursor(3,2);
            lcd.print("seconds");
          } else if(lcdInterval > 60) {
            minutes = lcdInterval / 60;
            lcd.setCursor(0,2);
            lcd.print(minutes);
            lcd.setCursor(3,2);
            lcd.print("minutes");
          }
          
        }
      }
      buttonState = buttonValue1;
                                
    }
  }
  
  lcd.setCursor(0,3);
  lcd.print("Starting");
  delay(400);
  for (int i = 0; i <= 2; i++) {
    lcd.print(".");
    delay(350);
  }
  return lcdInterval;
}




void lcdPrintDouble( double val, byte precision){


  if(val < 0.0){
    lcd.print('-');
    val = -val;
  }
  if (int(val) < 100) {
    lcd.print(" ");
    lcd.print(int(val));
  } else {
    lcd.print (int(val));  
  }
  if( precision > 0) {
    lcd.print(".");
    unsigned long frac;
    unsigned long mult = 1;
    byte padding = precision -1;
    while(precision--)
      mult *=10;

    if(val >= 0)
       frac = (val - int(val)) * mult;
    else
       frac = (int(val)- val ) * mult;
    unsigned long frac1 = frac;
    while( frac1 /= 10 )
     padding--;
    while(  padding--)
       lcd.print("0");
       lcd.print(frac,DEC) ;
  }
}

and this error mesagges
Code:
sketch_jul04a.cpp: In function 'void setup()':
sketch_jul04a:119: error: 'saveInt' was not declared in this scope
sketch_jul04a.cpp: In function 'void loop()':
sketch_jul04a:183: error: a function-definition is not allowed here before '{' token
sketch_jul04a:357: error: expected `}' at end of input
2  Using Arduino / Programming Questions / help my program please on: July 03, 2012, 09:56:57 pm
this is my program error

Code:
  saveInterval = saveInt(); //call saveInt sub-function and return value
  lcdInterval = lcdInt();   //call lcdInt sub-function and return value

and
Code:
int saveInt() {
  int buttonValue1;
  int buttonValue2;
  int buttonState;
  int minutes;

  lcd.clear();
  lcd.print("Choose save interval");
  delay(500);
  lcd.setCursor(0,1);
  lcd.print(saveInterval);
  lcd.setCursor(3,1);
  lcd.print("seconds");
  buttonState = digitalRead(button1);
 
 
    buttonValue1 = digitalRead(button1);
    delay(10);
    buttonValue2 = digitalRead(button1);
    if (buttonValue1 == buttonValue2) {
      if (buttonValue1 != buttonState) {
        if (buttonValue1 == LOW) {
          if (saveInterval >= 5 && saveInterval < 20) {
            saveInterval = saveInterval + 5; //set value to 5, 10, 15 or 20 seconds
          } else if(saveInterval >= 20 && saveInterval < 30) {
            saveInterval = saveInterval + 10; //set value to 30 seconds
          } else if(saveInterval >= 30 && saveInterval < 60) {
            saveInterval = saveInterval + 30; //set value to 60 seconds
          } else if(saveInterval >= 60 && saveInterval < 120) {
            saveInterval = saveInterval + 60; //set value to 120 seconds
          } else if(saveInterval >= 120 && saveInterval < 300) {
            saveInterval = saveInterval + 180; //set value to 5 minutes (300 seconds)
          } else if(saveInterval >= 300 && saveInterval < 600) {
            saveInterval = saveInterval + 300; //set value to 10 minutes (600 seconds)
          } else if(saveInterval >= 600) {
            saveInterval = 5; //circle back to 5 seconds after reaching 600 second option
          }
          //Show the user the current saveInterval value before the while loop starts over
          //again and checks for new button presses
          lcd.setCursor(0,1);
          lcd.print("   ");
          if (saveInterval <= 60) {
            lcd.setCursor(0,1);
            lcd.print(saveInterval);
            lcd.setCursor(3,1);
            lcd.print("seconds");
          } else if(saveInterval > 60) {
            minutes = saveInterval / 60;
            lcd.setCursor(0,1);
            lcd.print(minutes);
            lcd.setCursor(3,1);
            lcd.print("minutes");
          }
   
        }
      }
      buttonState = buttonValue1; //update buttonState so that only changes
                                  //in button status are registered
    }

 }//while loop has expired, show user that their choice is being stored
  lcd.setCursor(0,3);
  lcd.print("Storing");
  delay(400);
  for (int i = 0; i <= 2; i++) {
    lcd.print(".");
    delay(350);
  }
  return saveInterval;
} //end of saveInt sub-routine

and this is a messagge error

Code:
sketch_jul03c.cpp: In function 'void setup()':
sketch_jul03c:156: error: 'saveInt' was not declared in this scope
sketch_jul03c.cpp: In function 'void loop()':
sketch_jul03c:247: error: a function-definition is not allowed here before '{' token
sketch_jul03c:428: error: expected `}' at end of input
3  Using Arduino / Programming Questions / Re: error: expected constructor, destructor, or type conversion on: July 03, 2012, 01:42:04 pm
ok thanks
4  Using Arduino / Programming Questions / error: expected constructor, destructor, or type conversion on: July 03, 2012, 10:50:36 am
anyone help please i have a errors in this program

Code:
#include <SD.h>
#include <LiquidCrystal.h>

int CS_pin = 53;

volatile long lastSave = 0; // time value of last save. Relies on realtime clock
volatile long lcdTimeOut = 0; //timer for turning off LCD
volatile int saveInterval = 10; //time between saves (units = seconds, not millis)
volatile int lcdInterval= 60; //time to wait before shutting off LCD (units = seconds)
const int reps = 9; //number of temp readings to average per channel (count from zero)

LiquidCrystal lcd(8,3,4,5,6,7); //RS,EN,DB4,DB5,DB6,DB7


#define muxA0 15
#define muxA1 16
#define muxA2 17
#define tempPin 0
#define lcdLight 9
#define button1 2                   
int button1INT = 0;

#define aref_voltage 1.1

const int chs = 8;
const int numReadings = 10;
long tempInArray[numReadings][chs];
int index = 0;
long total[chs];
float averages[chs];

//*****************************************************************************************
void error(char *str)
{
  lcd.clear();
  lcd.home();
  lcd.print("error: ");
  lcd.print(str);
  while(1);
}

//****************************************************************************************

void setup(void)
{
  Serial.begin(9600);
  analogReference(INTERNAL1V1);
  pinMode(muxA2, OUTPUT);
  pinMode(muxA1, OUTPUT);
  pinMode(muxA0, OUTPUT);
  pinMode(button1, INPUT);
  digitalWrite(lcdLight, HIGH);

  lcd.begin(20,4);  //(columns,rows)
  lcd.setCursor(0,0);
  lcd.print("Tugas Akhir");
  lcd.setCursor(0,1);
  lcd.print("Miniatur Hujan Salju");
  delay (5000);
  lcd.clear();
 
  lcd.setCursor(0,0);
  lcd.print ("Oleh: ");
  lcd.setCursor(0,1);
  lcd.print ("Mochamad Rikki Firmansyah");
  lcd.setCursor(0,2);
  lcd.print ("dan");
  lcd.setCursor(0,3);
  lcd.print ("Ichsan T Primanizar");
  delay (5000);
  lcd.clear();
  //**************************************************************************
  //initialize the SD card
  if (!SD.begin(CS_pin))
    {
      lcd.setCursor(0,0);
      lcd.println ("Card Failure ");
      delay (3000);
      lcd.clear();
      return;
    }
      lcd.println ("Card Ready");
      delay (3000);
      lcd.clear();
     
  //Membaca Konfigurasi command.txt
  File commandFile = SD.open ("COMMAND.txt");
  if (commandFile)
  {
    lcd.setCursor(0,0);
    lcd.println ("Membaca File");
    delay (3000);
    lcd.clear();
    while (commandFile.available());
  }
  else
  {
    lcd.println ("File Tdk Trsedia");
    delay (3000);
    lcd.clear();
  }
 
 
  //Write log file
  File logFile = SD.open ("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println (", , , , , , , ,");
    String header = "Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8";
    logFile.println (header);
    logFile.close();
  }
  else
  {
    lcd.setCursor (0,0);
    lcd.print  ("data failed");
    delay (2000);
    lcd.clear();
  }
 
 
}

  //***************************************************************************
  // Have user select save-data interval and lcd timeout
  // These two lines call sub-routines that are down at the bottom of this file
  saveInterval = saveInt(); //call saveInt sub-function and return value
  lcdInterval = lcdInt();   //call lcdInt sub-function and return value
  //*******************************************************************************
 
  // initialize analog temperature value array

  for (int channel = 0; channel < chs; channel++) {
    for (int i = 0; i < numReadings; i++) {
      tempInArray[i][channel] = 0;
    }
  }

i had a errors is
Code:
sketch_jul03c:169: error: expected constructor, destructor, or type conversion before '=' token
sketch_jul03c:170: error: expected constructor, destructor, or type conversion before '=' token
sketch_jul03c:175: error: expected unqualified-id before 'for'
sketch_jul03c:175: error: expected constructor, destructor, or type conversion before '<' token
sketch_jul03c:175: error: expected constructor, destructor, or type conversion before '++' token
5  Using Arduino / Displays / help LCD error compilling on: June 24, 2012, 08:41:15 pm
I want to compile the LCD and suddenly appeared an error message like this

Code:
core.a(main.cpp.o): In function `main':
D:\Document\Work\arduino\mikrokontroler\1.Software\arduino-0023\hardware\arduino\cores\arduino/main.cpp:10: undefined reference to `loop'

and this is my library

Code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 3, 4, 5, 6, 7);

void setup() {
  lcd.begin(20,4);
  lcd.setCursor(0,0);
  lcd.print ("Tugas Akhir");
  lcd.setCursor(0,1);
  lcd.print ("Miniatur Hujan Salju Buatan");
  delay (5000);
  lcd.clear();
 
  lcd.setCursor(0,0);
  lcd.print ("Oleh : ");
  lcd.setCursor(0,1);
  lcd.print ("Mochamad Rikki Firmansyah");
  delay (3000);
  lcd.clear();
 
  lcd.setCursor(0,0);
  lcd.print ("Ichsan T Primanizar");
  delay (3000);
  lcd.clear();
 
  lcd.setCursor(0,0);
  lcd.print ("inisialisasi");
  lcd.setCursor (0,1);
  delay (5000);
    }
6  Using Arduino / Storage / ask for determining circuit SD card shield on: June 15, 2012, 11:26:20 pm
I want to make simulation program SD card and i have a problem to determining circuit SD card shield
i used the this SD card shield
http://iteadstudio.com/store/index.php?main_page=popup_image&pID=232

can anyone help me to determining circuit SD card shield
7  Using Arduino / Storage / Re: TinyFAT Library on: June 07, 2012, 09:24:52 am
any someone have a simulation for  Stackable SD Card Shield if we use Arduino?
8  Using Arduino / Programming Questions / Re: arduino mega 2560, LCD shield Arduino 16x2, and thermocouple on: May 07, 2012, 09:25:34 pm
sorry I'm still newbie in learn microcontroller

is there someone to explain the simulate? smiley-confuse
9  Using Arduino / Programming Questions / Re: arduino mega 2560, LCD shield Arduino 16x2, and thermocouple on: May 07, 2012, 11:37:48 am
try about sensor thermocouple and  displays to the LCD shield
10  Using Arduino / Programming Questions / arduino mega 2560, LCD shield Arduino 16x2, and thermocouple on: May 07, 2012, 10:21:12 am
I have arduino mega 2560, LCD shield Arduino 16x2, and thermocouple
I try to simulation, and i can't
any someone can tell me for simulation?
Pages: [1]