source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/advanced/m5_env3.rb
Ruby
mit
48
master
1,656
# # This example combines the SHTX and QMP6988 examples. The M5Stack ENV III unit # contains both sensors, accessible over a single I2C connection. # require 'bundler/setup' require 'denko' require_relative '../sensor/neat_tph_readings' # How many degrees C the two temperature values can differ by before a warning. TO...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/advanced/joystick_oled.rb
Ruby
mit
48
master
2,800
# # Move a square around an OLED screen with a Joystick. # require 'bundler/setup' require 'denko' # Joystick X_PIN = :A1 Y_PIN = :A2 connection = Denko::Connection::Serial.new board = Denko::Board.new(connection) joystick = Denko::AnalogIO::Joystick.new board: board, ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/advanced/rotary_encoder_mac_volume.rb
Ruby
mit
48
master
1,366
# # Example using a KY-040 (30 detent) rotary encoder as a mac volume control. # require 'bundler/setup' require 'denko' PIN_A = 4 PIN_B = 5 board = Denko::Board.new(Denko::Connection::Serial.new) encoder = Denko::DigitalIO::RotaryEncoder.new board: board, pins: { a:...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/eeprom/at24c.rb
Ruby
mit
48
master
786
# # AT24C256 EEPROM example # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) i2c = Denko::I2C::Bus.new(board: board) eeprom = Denko::EEPROM::AT24C.new(bus: i2c) # Addresses for the 256kib version are 0..32767. Each address holds 1 byte. # Write a byte to a single ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/eeprom/board.rb
Ruby
mit
48
master
882
# # Example showing how to load, modify and save the board's EEPROM. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # Initialization automatically gets all EEPROM data from the board. # eeprom = Denko::EEPROM::BuiltIn(board: board) eeprom = board.eeprom # EEPROM siz...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/ads1118.rb
Ruby
mit
48
master
2,207
# # Example using an ADS1118 ADC over the SPI bus. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) ads = Denko::AnalogIO::ADS1118.new(bus: bus, pin: 10) # Helper method so readings look nice. def print_reading(name, raw, vol...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/input_smoothing.rb
Ruby
mit
48
master
717
# # This example shows how to smooth the input of an AnalogIO::Input. # require 'bundler/setup' require 'denko' PIN = :A0 board = Denko::Board.new(Denko::Connection::Serial.new) input = Denko::AnalogIO::Input.new(pin: PIN, board: board) # Enable smoothing on the input using the last 16 values. input.smoothing = true...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/potentiometer.rb
Ruby
mit
48
master
880
# # Example for a potentiometer. # require 'bundler/setup' require 'denko' PIN = :A0 board = Denko::Board.new(Denko::Connection::Serial.new) pot = Denko::AnalogIO::Potentiometer.new(pin: PIN, board: board) # Tell connected Board to send a value every 8ms (default), and enable smoothing. pot.listen pot.smoothing = tr...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/ads1115.rb
Ruby
mit
48
master
1,976
# # Example using an ADS1115 ADC over the I2C bus. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::I2C::Bus.new(board: board) ads = Denko::AnalogIO::ADS1115.new(bus: bus) # Helper method so readings look nice. def print_reading(name, raw, voltage) p...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/ads1100.rb
Ruby
mit
48
master
1,427
# # Example using an ADS1100 ADC over the I2C bus. # require 'bundler/setup' require 'denko' # Helper method so readings look nice. def print_reading(name, raw, voltage) print "#{Time.now.strftime '%Y-%m-%d %H:%M:%S'} - " print "#{name.rjust(9, " ")} | " print "Raw: #{raw.to_s.rjust(6, " ")} | " print "Voltage...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/dac_loopback.rb
Ruby
mit
48
master
1,047
# # Example looping the Arduino Zero's DAC back into one of its ADC pins. # require 'bundler/setup' require 'denko' # # Arduino Zero: :DAC0 is :A0 is GPIO14 # Arduino UNO R4: :DAC is :A0 is GPIO14 # ESP32 V1: :DAC0 is GPIO25, :DAC1 is GPIO26, :A4 is GPIO32 # ESP32-S2: :DAC0 is GPIO17, :DAC1 is GPIO18, :...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/joystick.rb
Ruby
mit
48
master
996
# # Use a generic 2-axis (double potentiometer) joystick. # require 'bundler/setup' require 'denko' X_PIN = :A1 Y_PIN = :A2 board = Denko::Board.new(Denko::Connection::Serial.new) joystick = Denko::AnalogIO::Joystick.new board: board, pins: {x: X_PIN, y: Y_PIN}, ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/adkeyboard.rb
Ruby
mit
48
master
632
# # This is a small 5 button (D-pad + Enter) module, commonly sold as "AD Keyboard". # It uses a single analog input. Each button pulls the ADC value down to a # a different percentage of full scale, which can be detected. # require 'bundler/setup' require 'denko' PIN = :A0 board = Denko::Board.new(Denko::Connect...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/analog_io/input.rb
Ruby
mit
48
master
2,105
# # Use your board's analog-to-digital-converter(ADC) pins with AnalogIO::Input. # ADC inputs can be connected to sensors that produce variable output voltage, # such as light dependent resistors, or a temperature sensor like the TMP36. # require 'bundler/setup' require 'denko' PIN = :A0 board = Denko::Board.new(Denk...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/spi/loopback.rb
Ruby
mit
48
master
1,276
require 'bundler/setup' require 'denko' # Bit bang on same pins as hardware SPI for most Arduinos. SPI_BIT_BANG_PINS = { clock: 13, input: 12, output: 11 } SELECT_PIN = 10 board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) # bus = Denko::SPI::BitBang.new(board: boar...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/spi/two_registers.rb
Ruby
mit
48
master
1,078
# # 2 SPI registers (74HC595 and CD4021B) on the same bus, both acting as # BoardProxies for their Subcomponents. # require 'bundler/setup' require 'denko' # SPI pins (on board) SPI_BIT_BANG_PINS = { clock: 13, input: 12, output: 11 } OUT_REGISTER_SELECT = 10 IN_REGISTER_SELECT = 9 # LED and Button pins (on their ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/spi/input_register.rb
Ruby
mit
48
master
1,347
# # Button connected through input shift register (CD4021B). # require 'bundler/setup' require 'denko' # SPI pins (on board) SPI_BIT_BANG_PINS = { clock: 13, input: 12 } REGISTER_SELECT_PIN = 9 # Button pin (on register parallel outputs) BUTTON_PIN = 0 board = Denko::Board.new(Denko::Connection::Serial.new) bus ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/spi/output_register.rb
Ruby
mit
48
master
1,275
# # Example of LED connected through an output shift register (74HC595). # Can be used over either a bit bang or hardware SPI interface. # require 'bundler/setup' require 'denko' # SPI pins (on board) SPI_BIT_BANG_PINS = { clock: 13, output: 11 } REGISTER_SELECT_PIN = 10 # LED pin (on register parallel outputs) LED...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/connection/tcp.rb
Ruby
mit
48
master
499
# # Connect to a Board via TCP. This works for WiFi and Ethernet sketches. # Default port is 3466, and must match the port the Board was flashed to listen on. # require 'bundler/setup' require 'denko' IP_ADDRESS = "192.168.0.52" PORT = 3466 PIN = :LED_BUILTIN connection = Denko::Connection::TCP.new(I...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/connection/binary_echo.rb
Ruby
mit
48
master
800
# # Diagnostic to confirm board is receiving binary data # (in aux message) properly. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) echo = Denko::Connection::BinaryEcho.new(board: board, pin: 253) min_byte = 0 max_byte = 255 expected_result = (min_byte..max_byte)....
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/canvas_transforms.rb
Ruby
mit
48
master
1,304
# # Example showing how to transform the Canvas on pixel displays. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # Using SSD1306 OLED (128x64), connected over I2C. Change as needed. bus = Denko::I2C::Bus.new(board: board) display = Denko::Display::SSD1306.new(bus: b...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/ch1115_88x48.rb
Ruby
mit
48
master
904
# # Example for 88x48 I2C OLED (0.5"), using CH1115 driver. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::I2C::Bus.new(board: board) oled = Denko::Display::CH1115.new(bus: bus, width: 88, height: 48) # address: 0x3C is default # Draw some text on the OL...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/hd44780.rb
Ruby
mit
48
master
1,429
# # This example writes "Hello World!" in the display # require 'bundler/setup' require 'denko' # These pins match the SainSmart LCD Keypad Shield for Arduino boards. RS = 8 EN = 9 D4 = 4 D5 = 5 D6 = 6 D7 = 7 board = Denko::Board.new(Denko::Connection::Serial.new) lcd = Denko::Display::HD44780.new board: board, ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/canvas_path_polygon.rb
Ruby
mit
48
master
1,042
# # Example drawing paths (poly lines) and closed polygons on a Canvas # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # Using SSD1306 OLED (128x64), connected over I2C. Change as needed. bus = Denko::I2C::Bus.new(board: board) display = Denko::Display::SSD1306.new(bu...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/hd44780_thru_pcf8574.rb
Ruby
mit
48
master
1,558
# # This example writes "Hello World!" in the display # require 'bundler/setup' require 'denko' # These are PCF8574 pin numbers. Matches how the common "backpacks" connect to the LCD. RS = 0 RW = 1 # Must be given when using LCD with PCF8574, as it defaults high, but must be pulled low. EN = 2 BL = 3 # Must pull this ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/oled_64x32.rb
Ruby
mit
48
master
1,096
# # Example for 64x32 I2C OLED (0.49"), using SSD1306 driver. # Also for 64x48 I2C OLED (0.66") with SSD1306. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::I2C::Bus.new(board: board) oled = Denko::Display::SSD1306.new(bus: bus, width: 64, height: 32) # a...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/ssd1680.rb
Ruby
mit
48
master
1,291
# # Example using the SSD1680 E-Paper over SPI. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) # Must be connected to SPI bus CLK and MOSI pins, plus select, dc, reset and busy. # Give colors: as total number of colors NOT incl...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/ssd1681.rb
Ruby
mit
48
master
1,063
# # Example using the SSD1681 E-Paper over SPI. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) # Must be connected to SPI bus CLK and MOSI pins, plus select, dc, reset and busy. epaper = Denko::Display::SSD1681.new(bus: bus, pi...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/oled_128x64.rb
Ruby
mit
48
master
1,841
# # Generic example for 128x64 OLEDs. This covers both I2C and SPI versions of # SSD1306 and SH1106 at this pixel size. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # The OLED connects to either an I2C or SPI bus, depending on the model you have. bus = Denko::I2C::...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/il0373.rb
Ruby
mit
48
master
1,106
# # Example using the IL0373 E-Paper over SPI. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) # Must be connected to SPI bus CLK and MOSI pins, plus select, dc, reset and busy. epaper = Denko::Display::IL0373.new(bus: bus, pins...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/oled_72x40.rb
Ruby
mit
48
master
929
# # Example for 72x40 I2C OLED (0.42"), using SSD1306 driver. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::I2C::Bus.new(board: board) oled = Denko::Display::SSD1306.new(bus: bus, width: 72, height: 40) # address: 0x3C is default # Draw some text on the...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/st7302.rb
Ruby
mit
48
master
1,145
# # Example using the reflective ST7302 reflective LCD over SPI. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) # Must be connected to SPI bus CLK and MOSI pins, plus select, dc and reset. lcd = Denko::Display::ST7302.new(bus: ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/pcd8544.rb
Ruby
mit
48
master
1,662
# # Example using the PCD8544 (Nokia 5110) LCD over SPI. # It is 84 pixels wide x 48 pixels high. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) # Must be connected to SPI bus CLK and MOSI pins, plus select, dc and reset. lcd =...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/canvas_fonts.rb
Ruby
mit
48
master
882
# # Example showing how to use fonts on pixel displays. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # Using SSD1306 OLED (128x64), connected over I2C. Change as needed. bus = Denko::I2C::Bus.new(board: board) display = Denko::Display::SSD1306.new(bus: bus) # addre...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/canvas_eye_animation.rb
Ruby
mit
48
master
1,551
# # Example animating eyes that look around, made from primitive shapes. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # Using SSD1306 OLED (128x64), connected over I2C. Change as needed. bus = Denko::I2C::Bus.new(board: board) display = Denko::Display::SSD1306.new(...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/oled_128x32.rb
Ruby
mit
48
master
1,194
# # Generic example for 128x32 OLEDs, usually only SSD1306 over I2C. # Also covers the one built into the Lolin ESP32-S2 Pico. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # Modules usually have reset permanently tied high. # Lolin ESP32-S2 has it connected to pin ...
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/st7565.rb
Ruby
mit
48
master
1,188
# # Example using the ST7565 LCD over SPI. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) bus = Denko::SPI::Bus.new(board: board) # Must be connected to SPI bus CLK and MOSI pins, plus select, dc and reset. # On some modules reset: is marked as "RSE" and dc: as "RS"....
github
denko-rb/denko
https://github.com/denko-rb/denko
examples/display/oled_128x128.rb
Ruby
mit
48
master
1,107
# # Generic example for 128x128 OLEDs. This covers SH1107 for both I2C and SPI. # require 'bundler/setup' require 'denko' board = Denko::Board.new(Denko::Connection::Serial.new) # The OLED connects to either an I2C or SPI bus, depending on the model you have. bus = Denko::I2C::Bus.new(board: board) # I2C OLED, conne...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko.rb
Ruby
mit
48
master
1,937
# Helpers needed during loading. require_relative 'denko/helpers' # Denko - Electronics Programming in Ruby # # Program real-life electronics in Ruby. LEDs, buttons, sensors (and more) # work just like any Ruby object. # # Denko provides a Ruby API for controlling physical peripherals while # abstracting hardware and ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko_cli.rb
Ruby
mit
48
master
409
module DenkoCLI require "denko_cli/parser" require "denko_cli/generator" TASKS = ["sketch"] SKETCHES = ["serial", "ethernet", "wifi"] def self.start(options={}) options = DenkoCLI::Parser.run(options) method = options[:task] self.send method, options end def self.sketch(options) resu...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko_cli/parser.rb
Ruby
mit
48
master
2,091
class DenkoCLI::Parser require 'denko_cli/helper' include DenkoCLI::Helper def initialize(options={}) @options = options end def self.run(options={}) self.new(options).parse end def parse # Ensure we have arguments. args = @options[:args].dup error("No arguments given") if args.empt...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko_cli/helper.rb
Ruby
mit
48
master
617
module DenkoCLI::Helper def error(message, help=:usage) $stderr.puts $stderr.puts "Error: #{message}" $stderr.puts usage if help == :usage targets if help == :targets end def usage text = File.read(File.join(@options[:cli_dir], "usage.txt")) $stderr.print text $stderr.puts exi...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko_cli/targets.rb
Ruby
mit
48
master
935
class DenkoCLI::Generator STANDARD_PACKAGES = PACKAGES.each_key.map do |package| package unless PACKAGES[package][:only] end.compact TARGETS = { # Core is core. core: [:core], # Specific features for the old mega168 chips. atmega168: [:core, :tone, :i2...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko_cli/packages.rb
Ruby
mit
48
master
2,050
class DenkoCLI::Generator # File locations are defined relative to the src/lib directory. PACKAGES = { # The core package is always included. core: { description: "Core Denko Library", directive: nil, files: [ "Denko.h", "DenkoDefines.h", "Denko.cpp", "DenkoCoreIO.cpp", "D...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko_cli/generator.rb
Ruby
mit
48
master
5,088
class DenkoCLI::Generator require "fileutils" require "denko_cli/packages" require "denko_cli/targets" require "denko/version" require "denko_cli/helper" include DenkoCLI::Helper attr_accessor :options def initialize(options={}) @options = options append_target end def append_target ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/led.rb
Ruby
mit
48
master
707
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. LED_FILES = [ [nil, "base"], [:RGB, "rgb"], [:SevenSegment, "seven_segment"], [:WS2812, "ws2812"], [:APA102, "apa102"], [:SevenSegmentArray, "seven_segment_ar...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/rtc.rb
Ruby
mit
48
master
378
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. RTC_FILES = [ [:DS3231, "ds3231"], ] module Denko module RTC RTC_FILES.each do |file| file_path = "#{__dir__}/rtc/#{file[1]}" if file[0] autoload file[0], file_path e...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/digital_io.rb
Ruby
mit
48
master
740
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. DIGITAL_IO_FILES = [ [:Input, "input"], [:Output, "output"], [:Button, "button"], [:Relay, "relay"], [:RotaryEncoder, "rotary_encoder"], [:PCF8574, ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/board.rb
Ruby
mit
48
master
3,838
# Require all files in board folder relative to this file. Dir["#{Denko.root}/lib/denko/board/*.rb"].each { |file| require file } module Denko class Board attr_reader :name, :version, :serial_buffer_size, :aux_limit, :eeprom_length, :i2c_limit attr_reader :low, :high, :analog_write_resolution, :analog_read_r...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io.rb
Ruby
mit
48
master
710
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. ANALOG_IO_FILES = [ [:InputHelper, "input_helper"], [:Input, "input"], [:Output, "output"], [:Potentiometer, "potentiometer"], [:Joystick, "joystick"], [:ADKeyboa...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection.rb
Ruby
mit
48
master
405
module Denko module Connection autoload :FlowControl, "#{__dir__}/connection/flow_control" autoload :Handshake, "#{__dir__}/connection/handshake" autoload :Base, "#{__dir__}/connection/base" autoload :Serial, "#{__dir__}/connection/serial" autoload :TCP, "#{__dir__}/conn...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display.rb
Ruby
mit
48
master
1,011
require_relative "display/font" # Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. DISPLAY_FILES = [ # Character Displays [:HD44780, "hd44780"], # Pixel display mixins and helpers [:PixelCommon, "pixel_common"], [:SPICommon, "sp...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/motor.rb
Ruby
mit
48
master
428
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. MOTOR_FILES = [ [:Servo, "servo"], [:A3967, "a3967"], [:L298, "l298"], ] module Denko module Motor MOTOR_FILES.each do |file| file_path = "#{__dir__}/motor/#{file[1]}" if f...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/spi.rb
Ruby
mit
48
master
633
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. SPI_FILES = [ [:BusCommon, "bus_common"], [:Bus, "bus"], [:BitBang, "bit_bang"], [:ChipSelect, "peripheral"], [:Peripheral, "peripheral"], [:Register, "...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/behaviors.rb
Ruby
mit
48
master
1,238
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. BEHAVIORS_FILES = [ # Pin and component setup stuff [:Lifecycle, "lifecycle"], [:State, "state"], [:Component, "component"], [:SinglePin, "single_pin"], [:InputPin, "input_pin"], ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/sensor.rb
Ruby
mit
48
master
1,014
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. SENSOR_FILES = [ [nil, "helper"], [:DHT, "dht"], [:DS18B20, "ds18b20"], [:BMP180, "bmp180"], [:BME280, "bme280"], [:BMP280, "bme280"], [:HDC1080, "...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/uart.rb
Ruby
mit
48
master
441
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. UART_FILES = [ [nil, "common"], [:Hardware, "hardware"], [:BitBang, "bit_bang"], ] module Denko module UART UART_FILES.each do |file| file_path = "#{__dir__}/uart/#{file[1]...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/i2c.rb
Ruby
mit
48
master
470
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. I2C_FILES = [ [:BusCommon, "bus_common"], [:Bus, "bus"], [:BitBang, "bit_bang"], [:Peripheral, "peripheral"], ] module Denko module I2C I2C_FILES.each do |file| file_pat...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/one_wire.rb
Ruby
mit
48
master
541
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. ONE_WIRE_FILES = [ [:Constants, "constants"], [:Helper, "helper"], [:BusEnumerator, "bus_enumerator"], [:Bus, "bus"], [:Peripheral, "peripheral"], ] module Denko...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/pulse_io.rb
Ruby
mit
48
master
493
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. PULSE_IO_FILES = [ # Pin and component setup stuff [:PWMOutput, "pwm_output"], [:Buzzer, "buzzer"], [:IROutput, "ir_output"], ] module Denko module PulseIO PULSE_IO_FILES.each do |fi...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/eeprom.rb
Ruby
mit
48
master
411
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. EEPROM_FILES = [ [:Board, "board"], [:AT24C, "at24c"], ] module Denko module EEPROM EEPROM_FILES.each do |file| file_path = "#{__dir__}/eeprom/#{file[1]}" if file[0] au...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/message.rb
Ruby
mit
48
master
2,769
module Denko module Message BYTE_MAX = 255 VAL_MIN = 0 VAL_MAX = 9999 def self.encode(command: nil, pin: nil, value: nil, aux_message: nil) # Optimized single byte binary message for digital write on pins 0..63. if (command == 1) && (pin < 64) && (value == 1 || value == 0) return ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/input_helper.rb
Ruby
mit
48
master
1,194
module Denko module AnalogIO module InputHelper # # Smoothing features. # Does a moving average of the last smoothing_size readings. # attr_accessor :smoothing, :smoothing_size def smoothing_size @smoothing_size ||= 8 end def smoothing_set @smoothi...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/ads1118.rb
Ruby
mit
48
master
1,569
module Denko module AnalogIO class ADS1118 include SPI::Peripheral include Behaviors::Lifecycle include ADS111X # Config register values on startup. MSB-first. # Matches datasheet. Same as: [0x05, 0x8B] or [5, 139] CONFIG_STARTUP = [0b00000101, 0b10001011] # Base config...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/output.rb
Ruby
mit
48
master
403
module Denko module AnalogIO class Output include Behaviors::OutputPin include Behaviors::Callbacks include Behaviors::Threaded include Behaviors::Lifecycle interrupt_with :write before_initialize do params[:mode] = :output_dac end def write(value) ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/joystick.rb
Ruby
mit
48
master
1,930
module Denko module AnalogIO class Joystick include Behaviors::MultiPin include Behaviors::Lifecycle def initialize_pins proxy_pin(:x, AnalogIO::Input) proxy_pin(:y, AnalogIO::Input) end after_initialize do # Midpoint as float @mid = board.adc_high ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/input.rb
Ruby
mit
48
master
1,760
module Denko module AnalogIO class Input include Behaviors::InputPin include Behaviors::Poller include Behaviors::Listener include InputHelper include Behaviors::Lifecycle before_initialize do # Allow giving ADC unit with multiple pins as a board proxy. if para...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/adkeyboard.rb
Ruby
mit
48
master
1,372
module Denko module AnalogIO class ADKeyboard < Input include Behaviors::InputRegister include Behaviors::Lifecycle BYTES = 1 # All virtual "pins" high by default. UNPRESSED_STATE = [0b11111] # Threshold voltages (as percent of board.adc_high) for each button. ADC_THRE...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/ads1115.rb
Ruby
mit
48
master
1,297
module Denko module AnalogIO class ADS1115 include Behaviors::Lifecycle include I2C::Peripheral include ADS111X I2C_ADDRESS = 0x48 I2C_FREQUENCY = 400_000 # Config register values on startup. MSB-first. # Matches datasheet, except MSB bit 7 unset to avoid conversion s...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/ads1100.rb
Ruby
mit
48
master
4,013
module Denko module AnalogIO class ADS1100 include Behaviors::Lifecycle include I2C::Peripheral include Behaviors::Poller include InputHelper I2C_ADDRESS = 0x48 I2C_FREQUENCY = 400_000 # Convert sample rates in samples-per-seconds to their bit representation. SA...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/analog_io/ads111x.rb
Ruby
mit
48
master
4,703
module Denko module AnalogIO module ADS111X # # Functionality shared among the ADS111X class of ADC converters. # include Behaviors::Reader attr_accessor :config_register, :active_pin, :active_gain PGA_SETTINGS = [ # Bitmask Full scale voltage 0.0001875, # 0b00...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/rtc/ds3231.rb
Ruby
mit
48
master
1,107
module Denko module RTC class DS3231 include I2C::Peripheral I2C_ADDRESS = 0x68 # Write start register 0x00, then bytes to set time. def time=(time) i2c_write [0] + time_to_bcd(time) time end # Do a blocking read when #time is called. alias :time :read ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/eeprom/board.rb
Ruby
mit
48
master
1,798
module Denko module EEPROM class Board include Behaviors::Component include Behaviors::Reader def max_eeperom_txn @max_eeeprom_txn ||= board.aux_limit - 3 end def length board.eeprom_length end def pin 254 end def [](loc) if...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/eeprom/at24c.rb
Ruby
mit
48
master
1,853
module Denko module EEPROM class AT24C include I2C::Peripheral I2C_ADDRESS = 0x50 I2C_FREQUENCY = 400_000 READ_WRITE_US = 20_000 WRITE_PAGE_SIZE = 64 def int_to_reg_array(int) [ (int >> 8) & 0xFF, int & 0xFF ] end def [](loc) if loc.class ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/st7302.rb
Ruby
mit
48
master
7,364
module Denko module Display class ST7302 include Behaviors::Lifecycle include SPICommon # Commands SWRESET = 0x01 DISPOFF = 0x28 DISPON = 0x29 OSC_EN = 0xC7 BSTEN = 0xD1 SLPIN = 0x10 SLPOUT = 0x11 HPM = 0...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/il0373.rb
Ruby
mit
48
master
5,201
module Denko module Display class IL0373 include SPIEPaperCommon include Behaviors::Lifecycle COLUMNS = 212 ROWS = 104 # Subset of used commands from datasheet: PANEL_SETTING = 0x00 POWER_SETTING = 0x01 POWER_OFF = 0x02 P...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/canvas.rb
Ruby
mit
48
master
14,435
module Denko module Display class Canvas attr_reader :columns, :rows, :framebuffer, :framebuffers, :colors def initialize(columns, rows, colors: 1) @columns = columns @rows = rows @rows = ((rows / 8.0).ceil * 8) if (rows % 8 != 0) # Use a byte array for the fr...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/mono_oled.rb
Ruby
mit
48
master
7,836
module Denko module Display module MonoOLED include Behaviors::BusPeripheral include Behaviors::Lifecycle # I2C Defaults I2C_ADDRESS = 0x3C I2C_FREQUENCY = 400_000 # Fundamental Commands # Single byte (no need to OR with anything) PIXELS_FROM_RAM = 0xA4 ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/spi_epaper_common.rb
Ruby
mit
48
master
619
module Denko module Display module SPIEPaperCommon include SPICommon # Defaults. Override in subclasses as needed. BUSY_WAIT_TIME = 0.005 RESET_TIME = 0.010 def initialize_pins super proxy_pin :busy, DigitalIO::Input, board: bus.board busy.stop end...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/ch1115.rb
Ruby
mit
48
master
387
module Denko module Display class CH1115 include MonoOLED COLUMNS = 88 ROWS = 48 RAM_P_OFFSET = 1 # Deal with unusual memory layout. def reflect_x @ram_x_offset = (@ram_x_offset == 0) ? 40 : 0 super end def reflect_y @ram_p_offset = (@ra...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/ssd1680.rb
Ruby
mit
48
master
282
module Denko module Display class SSD1680 < SSD168X COLUMNS = 296 ROWS = 128 # SSD1680 needs an extra byte here to offset source start by 8 pixels. def set_display_update_control super data [0b1000_0000] end end end end
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/font.rb
Ruby
mit
48
master
481
# Represent files to be autoloaded in CRuby as an Array. # This allows Mruby::Build to parse and preload them instead. FONT_FILES = [ [:BMP_5X7, "bmp_5x7"], [:BMP_6X8, "bmp_6x8"], [:BMP_8X16, "bmp_8x16"], ] module Denko module Display module Font FONT_FILES.each do |file| file_path = "#{__d...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/spi_common.rb
Ruby
mit
48
master
864
module Denko module Display module SPICommon include SPI::Peripheral include PixelCommon # # SPI displays use a D/C pin to toggle whether bytes being sent are data or commands. # Most also have a RESET pin which is pulsed low to initalize, then held high. # def initializ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/pcd8544.rb
Ruby
mit
48
master
4,055
module Denko module Display class PCD8544 include Behaviors::Lifecycle include SPICommon COLUMNS = 84 ROWS = 48 FUNCTION_SET = 0b00100000 # OR these options into lowest 3 bits: POWER_UP = 0b000 POWER_DOWN = 0b100 H_ADDRESSING = 0b00 V_ADDRE...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/pixel_common.rb
Ruby
mit
48
master
1,757
module Denko module Display module PixelCommon def columns return @columns if @columns @columns = self.class.const_get("COLUMNS") if self.class.const_defined?("COLUMNS") @columns = params[:width] if params[:width] @columns = params[:columns] if params[:columns] @colum...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/st7565.rb
Ruby
mit
48
master
4,889
module Denko module Display class ST7565 include Behaviors::Lifecycle include SPICommon COLUMNS = 128 ROWS = 64 # Overall commands RESET = 0b11100010 DISPLAY_ON = 0b10101111 DISPLAY_OFF = 0b10101110 ALL_POINTS_OFF ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/ssd168x.rb
Ruby
mit
48
master
7,924
module Denko module Display class SSD168X include Behaviors::Lifecycle include SPIEPaperCommon # Used by #hw_reset RESET_TIME = 0.010 # Typical Commands SW_RESET = 0x12 DRIVER_OUTPUT_CTL = 0x01 # +3 data DATA_ENTRY_MODE_SET = 0x11 # +1 dat...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/hd44780.rb
Ruby
mit
48
master
9,069
module Denko module Display # Ruby implementation of Hitachi HD44780 LCD support, based on the # Adafruit_LiquidCrystal library, # # @see https://github.com/adafruit/Adafruit_LiquidCrystal class HD44780 include Behaviors::MultiPin include Behaviors::Lifecycle # Commands LC...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/ssd1312.rb
Ruby
mit
48
master
215
module Denko module Display class SSD1312 include MonoOLED include Behaviors::Lifecycle # Reverse default reflection. after_initialize do reflect_x end end end end
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/ssd1306.rb
Ruby
mit
48
master
253
module Denko module Display class SSD1306 include MonoOLED include Behaviors::Lifecycle after_initialize do @ram_x_offset = 32 if (columns == 64) @ram_x_offset = 28 if (columns == 72) end end end end
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/font/bmp_6x8.rb
Ruby
mit
48
master
6,934
module Denko module Display module Font # MIT License # # Copyright (c) 2018-2019, Alexey Dynda # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Softwa...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/font/bmp_5x7.rb
Ruby
mit
48
master
6,360
module Denko module Display module Font # MIT License # # Copyright (c) 2018-2019, Alexey Dynda # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Softwa...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/display/font/bmp_8x16.rb
Ruby
mit
48
master
12,842
module Denko module Display module Font # MIT License # # Copyright (c) 2018-2019, Alexey Dynda # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Softwa...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection/base.rb
Ruby
mit
48
master
1,594
require 'observer' require 'timeout' module Denko module Connection class SerialConnectError < StandardError; end class RxFlushTimeout < StandardError; end class Base include Observable include Handshake # We need the methods in FlowControl to wrap subclass methods too. def s...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection/handshake.rb
Ruby
mit
48
master
1,778
module Denko module Connection class HandshakeError < StandardError; end class HandshakeAttempt attr_reader :acknowledged, :result def initialize @acknowledged = false @result = nil end def update(line) if line.match(/\AACK:/) @result = line.split(":...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection/binary_echo.rb
Ruby
mit
48
master
330
module Denko module Connection class BinaryEcho include Behaviors::SinglePin include Behaviors::Reader def test_range(min:0, max:255) bytes = (min..max).to_a board.binary_echo(pin, bytes) end def test_array(arr) board.binary_echo(pin, arr) end end ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection/board_uart.rb
Ruby
mit
48
master
523
module Denko module Connection class BoardUART < Base DEFAULT_BAUD = 115200 def initialize(uart, baud: DEFAULT_BAUD) @uart = uart @uart.start(baud) end def baud @uart.baud end def flush_read @uart.flush end def to_s "#{@ua...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection/flow_control.rb
Ruby
mit
48
master
4,496
module Denko module Connection module FlowControl SLEEP_TIME = 0.001 # Let Board object tell us the remote buffer size after parsing handshake. def remote_buffer_size=(size) @transit_mutex.synchronize { @remote_buffer_size = size } end def initialize(*args, **kwargs) ...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection/serial.rb
Ruby
mit
48
master
2,224
require 'rubyserial' module Denko module Connection class Serial < Base BAUD = 115200 def initialize(options={}) @device = options[:device] @baud = options[:baud] || BAUD @rx_buffer = String.new @rx_line = String.new @rx_escaped = false end...
github
denko-rb/denko
https://github.com/denko-rb/denko
lib/denko/connection/tcp.rb
Ruby
mit
48
master
862
require 'socket' module Denko module Connection class TCPConnectError < StandardError; end class TCP < Base def initialize(host="127.0.0.1", port=3466) @host = host @port = port end def to_s "#{@host}:#{@port}" end private def connect prin...