Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Trouble with programming logic on: January 20, 2013, 06:36:32 pm
I have tried to use return but it stops the program for a moment then continues. Like i said i'm new to this. I could rewrite it to while loops but, if you could write specific line to exit count() it would be helpfull. I have tried return, break, even goto but nothing seems to work
2  Using Arduino / Programming Questions / Re: Trouble with programming logic on: January 20, 2013, 05:47:18 pm
After 8 hours of working i was able to make my program work. There were many mistakes, mostly in coding. Every thing works great except when counting startstop button won't go to loop: If anybody have some sugestions would be most appreciated. The problematic part is commented, its in "count" function.
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int SSB = 6;
const int RB = 7;
const int PB= 8;
int StartStop=0;
int Reset=0;
int Setup=0;
int htime=1, mtime=58, stime=54;

void setup()
{
  Serial.begin(9600);
  lcd.begin(20, 4);
  lcd.print("Count");
  lcd.setCursor(3,1);
  lcd.print(":");
  lcd.setCursor(7,1);
  lcd.print(":"); 
  pinMode(SSB, INPUT);
  pinMode(RB, INPUT);
  pinMode(PB, INPUT); 
}
void loop()
{
  delay(100);
  Reset=digitalRead(RB);
  delay(50);
  if (Reset == HIGH){htime=0; mtime=0; stime=0;}
  lcd.setCursor(9, 1);
  lcd.print(stime);
  lcd.setCursor(5, 1);
  lcd.print(mtime);
  lcd.setCursor(1, 1);
  lcd.print(htime);
  StartStop=digitalRead(SSB);
  delay(50);
  if(StartStop == HIGH){count();}
  Setup=digitalRead(PB);
  delay(50);
  if (Setup==HIGH)
  {
    lcd.setCursor(9, 1);
    stime++;
    lcd.print(stime);
    Serial.print(stime);
    if (stime>=60)
    {
      stime=0;
      lcd.setCursor(5, 1);
      mtime++;
      lcd.print(mtime);
      Serial.print(mtime);
      if (mtime>=60)
      {
        mtime=0;
        lcd.setCursor(1, 1);
        htime++;
        lcd.print(htime);
        Serial.print(htime);
      }
    }
  }
}
void count()
{
  do
  {
    do
      {
        do
          {
            StartStop=digitalRead(SSB);
            delay(10);
            if(StartStop == HIGH) {loop();}                                                     //this thing here for some reason won't work
            Reset=digitalRead(RB);
            if (Reset == HIGH){ htime=0; mtime=0; stime=0; loop();};               //reset works, but jump to loop won't
            delay(10);
            lcd.setCursor(9, 1);
            stime--;
            lcd.print(stime);
            Serial.print(stime);
            //delay(16);
           }while(stime>0);
        lcd.setCursor(5, 1);
        mtime--;
        lcd.print(mtime);
         Serial.print(mtime);
        if (mtime>0){stime=60;}
      }while(mtime>0);
      lcd.setCursor(1, 1);
      htime--;
      lcd.print(htime);
      Serial.print(htime);
      if (htime>0){mtime=60;}
  }while(htime>=0);
}
3  Using Arduino / Programming Questions / Re: Trouble with programming logic on: January 20, 2013, 12:59:29 pm
Thank allot, this is a great reference. Trouble is that this is my school assingment, and is very specific. Time must be fastened. I real second my timer must count 60 seconds. Thats why i tried using delaymicros.
4  Using Arduino / Programming Questions / Re: Trouble with programming logic on: January 20, 2013, 12:40:01 pm
I'm new at this so some mistakes are expected smiley I changed the count so it doesn't use loop, but return. Count function should count backward to 0, from the previusly set variables htime, mtime and stime. I will edit my first post to comment that. thx
5  Using Arduino / Programming Questions / Re: Trouble with programming logic on: January 20, 2013, 12:26:47 pm
After further testing, i thing that the problem is with the function, because after clicking startstop button program doesn't enter count subroutine
6  Using Arduino / Programming Questions / Re: Trouble with programming logic on: January 20, 2013, 12:04:05 pm
Thanks for the quick reply. Buttons work, i tested it in different code, where i count every time i press it. They are not disconnected or anything. I just realized that reset works, but because of LCD i thought it doesn't work(LCD resets first number, and when coundown reaches next digit it overwrite the previous.) There is still problem with StartStop
Quote
stime==0;

should be stime = 0;
i would never see that smiley
7  Using Arduino / Programming Questions / Trouble with programming logic on: January 20, 2013, 11:50:48 am
Hello. I tried to do a basic countdown timer, that shows output on LCD. This is the code
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int SSB = 6;// StartStop button
const int RB = 7;// Reset button
const int PB= 8;//Setup button
int StartStop=0;
int Reset=0;
int Setup=0;
int htime=0, mtime=0, stime=0; // variables for hours, minutes and seconds

void setup()
{
  lcd.begin(20, 4);
  lcd.print("Countdown timer");
  lcd.setCursor(2,1);
  lcd.print(":");//printing separation marks
  lcd.setCursor(5,1);
  lcd.print(":");  //printing separation marks
  pinMode(SSB, INPUT);
  pinMode(RB, INPUT);
  pinMode(PB, INPUT);  
}

void loop()
{
  Reset=digitalRead(RB);
  delay(50);
  if (Reset == HIGH){htime=0; mtime=0; stime=0;}//if reset is pressed all time variables go to 0
  lcd.setCursor(6, 1);//used to print all zeros on LCD
  lcd.print(stime);//used to print all zeros on LCD
  lcd.setCursor(3, 1);//used to print all zeros on LCD
  lcd.print(mtime);//used to print all zeros on LCD
  lcd.setCursor(3, 1);//used to print all zeros on LCD
  lcd.print(htime);//used to print all zeros on LCD
  StartStop=digitalRead(SSB);//if start is presed program goes to count function
  delay(50);
  if(StartStop == HIGH){count;}//if start is presed program goes to count function
  Setup=digitalRead(PB);
  delay(50);
  if (Setup==HIGH)//if setup is pressed stime is incremented.
  {
    lcd.setCursor(6, 1);
    stime++;
    lcd.print(stime);
    if (stime>=60) //after stime reaches 60 seconds it should increment mtime, reset stime to 0 and start counting again.
    {
      stime==0;
      lcd.setCursor(3, 1);
      mtime++;
      lcd.print(mtime);
      if (mtime>=60)
      {
        mtime=0;
        lcd.setCursor(3, 1);
        htime++;
        lcd.print(htime);
      }
    }
  }
}
void count()// count function
{
  do
  {
    do
      {
        do
          {
            lcd.setCursor(6, 1);
            stime--;//program enters this do-while loop and decrement stime to 0 and then mtime, and htime
            lcd.print(stime);
            delayMicroseconds(16667);//specific delay because I need it to go faster then seconds
            if(StartStop == HIGH) {loop;}//if startstop button is pressed program jumps to loop -> changed "loop" to "return"
            if (Reset == HIGH){htime=0; mtime=0; stime=0; loop;};//resets time variables and jumps to loop-> changed "loop" to "return"
          }while(stime>=0);
        lcd.setCursor(3, 1);
        mtime--;
if (mtime>0){stime=60;}// added this line. count shoud be countdown timer with specific time
        lcd.print(mtime);
      }while(mtime>=0);
      lcd.setCursor(3, 1);
      //lcd.print(htime);
      htime--;
if (htime>0){mtime=60;}// added this line. count shoud be countdown timer with specific time
      lcd.print(htime);
  }while(htime<=0);
}

My problem is in loop, where stime should be reseted it keeps counting to 61, 62, and further. Also reset and startstop doesn't work. I tested button they are connected properly, and LCD works.
8  Using Arduino / Displays / Re: Formatting the output, JHD204A LCD on: January 04, 2013, 08:23:28 pm
Thanks for quick reply. I will try this.
9  Using Arduino / Displays / Formatting the output, JHD204A LCD on: January 04, 2013, 06:02:05 pm
Hello, i'm new here and i have a question.
I connected the JHD204a LCD display to Arduino Duemilanove. I get positioning the cursor, and printing simple things. Now i started another project and i need help. Is there any way to print something like this
Code:
The values are: X;Y;Z;//X,Y,Z are variables

I started like this:
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int x = 0;
int y = 0;
int z = 0;

void setup() {
  lcd.begin(20, 4);
  lcd.print("Hello World");
}

void loop() {
  lcd.setCursor(0, 1);
  x=millis()/1000;
  lcd.print(x);
  lcd.setCursor(2, 1);
  lcd.print(";");
  y=x*2;
  lcd.setCursor(3, 1);
  lcd.print(y);
  z=y*2;
  lcd.setCursor(5, 1);
  lcd.print(";");
  lcd.setCursor(6, 1);
  lcd.print(z);
}
This prints pretty much what i need, until some of the variables reach 3-digits, then print overlaps. Is there any way to automatically move the ";" markers to make room for more digits. Thx in advance smiley
Pages: [1]