By @quakewang
Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.
flashing LED
flashing LED
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
... Because ...
Ruby Arduino Development
DSL, ruby2c
gem install rad
rad my_sketch
class MySketch < ArduinoSketch
output_pin 13, :as => :led
def loop
blink led, 1000
end
end
rake make:upload
Only Support Ruby 1.8
Inactive development
Write - Upload - Run
http://ruby-serialport.rubyforge.org/
Ruby code
require 'rubygems'
require 'serialport'
sp = SerialPort.new "/dev/ttyUSB0", 9600
sp.write "abcd"
Arduino code
int b = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
b = Serial.read();
Serial.print("I received: ");
Serial.println(b, DEC);
}
}
Ruby Code
require 'rubygems'
require 'serialport'
sp = SerialPort.new "/dev/ttyUSB0", 9600
string = "12311231345-345-5.6_5.4_315.6_5.4_31151-151-0"
string.scan(/\d[_|\-|\.]?/) do |i|
sp.write i.ljust(2, '*')
end
Arduino Code
c = Serial.read();
if (c == '-') {
delay(1600);
} else if (c == '.') {
delay(600);
} else if (c == '*') {
delay(400);
} else if (c == '_') {
delay(200);
} else if (c == '0') {
noTone(8);
} else {
tone(8, pitches[c - '0']);
}
require 'rubygems'
require 'sinatra'
require 'arduino_firmata'
arduino = ArduinoFirmata.connect
get '/' do
analog = arduino.analog_read(0)
temperature = analog * 100 * 5.0 / 1023
"Now Temperature: #{temperature.round(2)}"
end
http://localhost:4567/
With Infrared Ray
With Infrared Ray
require 'rubygems'
require 'sinatra'
require 'serialport'
sp = SerialPort.new "/dev/ttyUSB0", 9600
get '/switch' do
sp.write("1")
"<a href='/switch'>switch</a>"
end
http://localhost:4567/switch
With Relay
Using Lava Lamps for Continuous Integration
Twitter Enabled Coffee Pot
http://www.instructables.com/id/Tweet-a-Pot-Twitter-Enabled-Coffee-Pot/Raspberry pi
Ubuntu on MK802
Trying...