I've built to build a timer that shows the content in a 16x2 LCD.
So far so good. Now, what I want to achieve is that when I push a button, pause the timer.
I'm using ruby, with the library rpi_gpio and
This is my code:
require 'rpi_gpio' require 'charlcd' RPi::GPIO.set_numbering :bcm RPi::GPIO.setup 18, :as => :input, :pull => :up lcd = CharLcd.new lcd.begin(16, 2) lcd.clear total_seconds = 0 start_time = Time.now t = Thread.new do loop do sleep 1 total_seconds = Time.now - start_time hours = (total_seconds/ 3600).to_i minutes = ((total_seconds % 3600) / 60).to_i seconds = ((total_seconds % 3600) % 60).to_i lcd.clear tim = hours.to_s.rjust(2, '0') + ':' + minutes.to_s.rjust(2, '0') + ':' + seconds.to_s.rjust(2, '0') lcd.message(tim) end end while RPi::GPIO.high? 18 do end t.kill lcd.clean_pins()
The problem comes when, as far as I know, the only way to control when button is pushed is with a loop, and I think two loops (the one of the timer and the one that controls the button) make slow the printing of the message in the LCD display.
I'm record this video to show you guys the behavior:
I'd be grateful if somebody could help me out with this, or give me another solution.
Thanks in advanced.