module self

enzi quick refference

digital IO

digitalWrite(D0, 1)

digiralRead(D1)

analog IO / PWM

analogWrite(D8, 255)

analogRead(A0)

SPI

spi = SPI.new(SPI::MSBFIRST, SPI::MODE0, SPI::CLOCK_DIV4)

result = spi.transfer(0xff)

Serial

s = Serial.new(9600)
while s.available
  print s.read
end
s.write("hello")

Wire (I2C)

wire = Wire.new(0x0, Wire::DutyCycle_2)
def read_register(register_address)
  @wire.beginTransmission(@target)
  @wire.write(register_address)
  @wire.endTransmission

  @wire.requestFrom(@target,1)
  return @wire.read
end
def write_register(register_address,value)
  @wire.beginTransmission(@target)
  @wire.write(register_address)
  @wire.write(value)
  @wire.endTransmission
end

Watchdog

w = WatchdogTimer.new