arduino 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in arduino.gemspec
4
+ gemspec
5
+ gem "serialport"
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "arduino/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "arduino"
7
+ s.version = Arduino::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Akash Manohar"]
10
+ s.email = ["akash@akash.im"]
11
+ s.homepage = ""
12
+ s.summary = %q{Arduino Prototyping API for Ruby}
13
+ s.description = %q{A library to talk to Arduino in Ruby without having to burn programs repeatedly to the board.}
14
+
15
+ s.rubyforge_project = "arduino"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,101 @@
1
+ module Arduino
2
+ require "serialport"
3
+
4
+ class Arduino
5
+
6
+ def initialize(port, baudrate=115200)
7
+ @serial = SerialPort.new port, baudrate
8
+ @serial.sync
9
+ @port = port #Cannot get connected port via SerialPort class
10
+ @outputPins = []
11
+ end
12
+
13
+ def to_s
14
+ "Arduino is on port #{@port} at #{@serial.baud} baudrate"
15
+ end
16
+
17
+ def output(*pinList)
18
+ sendData(pinList.length)
19
+
20
+ if pinList.class==Array
21
+ @outputPins = pinList
22
+ pinList.each do |pin|
23
+ sendPin(pin)
24
+ end
25
+ else
26
+ raise ArgumentError, "Arguments must be a list of pin numbers"
27
+ end
28
+ end
29
+
30
+ def getState(pin)
31
+ sendData('2')
32
+ sendPin(pin)
33
+ return formatPinState(getData())
34
+ end
35
+
36
+ def setLow(pin)
37
+ sendData('0')
38
+ sendPin(pin)
39
+ end
40
+
41
+ def setHigh(pin)
42
+ sendData('1')
43
+ sendPin(pin)
44
+ end
45
+
46
+ def analogWrite(pin, value)
47
+ sendData('3')
48
+ fullHexValue = value.to_s(base=16)
49
+ hexValue = hexValue[2..fullHexValue.length]
50
+ if(hexValue.length==1)
51
+ sendData('0')
52
+ else
53
+ sendData(hexValue[0])
54
+ end
55
+ sendData(hexValue[1])
56
+ end
57
+
58
+ def analogRead(pin)
59
+ sendData('4')
60
+ sendPin(pin)
61
+ getData()
62
+ end
63
+
64
+ def turnOff
65
+ @outputPins.each do |pin|
66
+ setLow(pin)
67
+ end
68
+ end
69
+
70
+ def close
71
+ @serial.close
72
+ end
73
+
74
+ private
75
+
76
+ def sendPin(pin)
77
+ pinInChar = (pin+48)
78
+ sendData(pinInChar)
79
+ end
80
+
81
+ def sendData(serialData)
82
+ while true
83
+ break if getData()=="?"
84
+ end
85
+ s = String(serialData.chr)
86
+ x = @serial.write (s)
87
+ end
88
+
89
+ def getData
90
+ cleanData = @serial.readlines()
91
+ cleanData = cleanData.join("").gsub("\n","").gsub("\r","")
92
+ end
93
+
94
+ def formatPinState(pinValue)
95
+ return 1 if pinValue=="1"
96
+ return 0 #if pinValue=="0"
97
+ #raise Exception, "Data/Connection error"
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module Arduino
2
+ VERSION = "0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arduino
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Akash Manohar
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-01-01 00:00:00 +05:30
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: A library to talk to Arduino in Ruby without having to burn programs repeatedly to the board.
21
+ email:
22
+ - akash@akash.im
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - .gitignore
31
+ - Gemfile
32
+ - Rakefile
33
+ - arduino.gemspec
34
+ - lib/arduino.rb
35
+ - lib/arduino/version.rb
36
+ has_rdoc: true
37
+ homepage: ""
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project: arduino
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Arduino Prototyping API for Ruby
68
+ test_files: []
69
+