I’ve been playing around with 7 segment displays on my RPI. I noticed
multiplexing in ruby doesn’t perform that well. I get flickring on the
displays and the ruby process eats up 10-20% of the RPI CPU.
Ruby -rprofile myprogram.rb shows that my display_segments method is the
culprit. I’m told that re-writing this in C could speed things up a bit
I started playing around with ruby inline. Admittedly I seem to get lost
the Ruby C API.
I’m pretty much an amateur but I thought I would post here for some
guidance from any willing kind hearted soul.
The culprit method is
def display_segments(num, display, io, delay = 0.005)
power = display.power
seg_pins = display.segments
pins = [:a, :b, :c, :d, :e, :f]
pins = [:b, :c]
pins = [:a, :b, :g, :e, :d]
seg_pins.each do |seg, pin|
pins.include?(seg) ? io.write(pin, LOW) : io.write(pin, HIGH)
I think the logic in my C method would be the same as my ruby one. The
where I run into trouble is converting values. For example I can’t
out how to decide which pins to light by hash key. In fact I can’t even
figure out how to get the hash keys…