Sha256: 4ce165c35484218c1121820c1980c7fbecd4a86dd321d2028d9ce6518063c4f9
Contents?: true
Size: 694 Bytes
Versions: 6
Compression:
Stored size: 694 Bytes
Contents
# # Example of playing a melody on a piezoelectric buzzer. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) buzzer = Denko::PulseIO::Buzzer.new(board: board, pin: 9) C4 = 262 D4 = 294 E4 = 330 notes = [ [E4, 1], [D4, 1], [C4, 1], [D4, 1], [E4, 1], [E4, 1], [E4, 2], [D4, 1], [D4, 1], [D4, 2], [E4, 1], [E4, 1], [E4, 2], [E4, 1], [D4, 1], [C4, 1], [D4, 1], [E4, 1], [E4, 1], [E4, 1], [E4, 1], [D4, 1], [D4, 1], [E4, 1], [D4, 1], [C4, 4], ] bpm = 240 beat_time = 60.to_f / bpm notes.each do |note| buzzer.tone(note[0]) sleep note[1] * beat_time end buzzer.stop board.finish_write
Version data entries
6 entries across 6 versions & 1 rubygems