#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0

    Trouble with variable and while/until


    i've been trying for hours now but I just cant get it to work:

    Code:
    delay = ARGV[0]
    
    timer = 0
    
      while TRUE do
        puts timer
        sleep (0.5)
        timer += 1
        break if timer == delay
      end
    i also tried untl

    Code:
    delay = ARGV[0]
    
    timer = 0
    
      until timer == delay
        puts timer
        sleep (0.5)
        timer += 1
      end
    i don't see what i am doing wrong, can somebody pleas tell me...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    191
    Rep Power
    49
    Code:
    delay1 = ARGV[0]
    puts delay1.class
    
    delay = ARGV[0].to_i
    puts delay.class
    timer = 0
    puts timer.class
    =begin
      while TRUE do
        puts timer
        sleep (0.5)
        timer += 1
        break if timer == delay
      end
    =end

    it probelm with the obects fixnum string
    Helmut Hagemann Germany

    fallen to the bottom of the facts?
    I reach my hand and we go together


    wer lesen und google kann ist klar im Vorteil
    who read and google is able is clear in the advantage
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0
    Originally Posted by xml-profi
    Code:
    delay1 = ARGV[0]
    puts delay1.class
    
    delay = ARGV[0].to_i
    puts delay.class
    timer = 0
    puts timer.class
    =begin
      while TRUE do
        puts timer
        sleep (0.5)
        timer += 1
        break if timer == delay
      end
    =end

    it probelm with the obects fixnum string
    Thanx, i already found a solution for my problem, but now i have the problem of a 2 second delay before the code is executed, i guess it has something to do with the while loop...

    the code is now as follows:

    Code:
    require "serialport.so"
    
    if ARGV.size < 1
     STDERR.print <<EOF
     1st_serial_port 2nd_delay_in_seconds 
    EOF
     exit(1)
    end
    
    sp = SerialPort.new(ARGV[0], 9600, 8, 1, SerialPort::NONE)
    
     delay = ARGV[1].to_i
      timer = 0
         
         while TRUE do
          sp.write "H\r\n" #sets pin 12 to HIGH
           puts timer
           timer += 1
           sleep(1)
          break if timer == delay
        end
        
         sp.write "L\r\n" #sets pin 12 to LOW
        sp.close
      puts
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    Try flushing your output stream before you sleep. ($stdout.flush)
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog

IMN logo majestic logo threadwatch logo seochat tools logo