atduskgreg-rad 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +104 -0
- data/License.txt +282 -0
- data/Manifest.txt +142 -0
- data/README.rdoc +55 -0
- data/Rakefile +142 -0
- data/bin/hello_world_test/Makefile +436 -0
- data/bin/hello_world_test/hello_world.cpp +23 -0
- data/bin/rad +302 -0
- data/lib/examples/add_hysteresis.rb +13 -0
- data/lib/examples/basic_blink.rb +10 -0
- data/lib/examples/blink_m_address_assignment.rb +104 -0
- data/lib/examples/blink_m_hello.rb +14 -0
- data/lib/examples/blink_m_multi.rb +61 -0
- data/lib/examples/blink_with_serial.rb +16 -0
- data/lib/examples/configure_pa_lcd_boot.rb +91 -0
- data/lib/examples/debounce_methods.rb +49 -0
- data/lib/examples/external_variable_fu.rb +26 -0
- data/lib/examples/external_variables.rb +32 -0
- data/lib/examples/first_sound.rb +23 -0
- data/lib/examples/frequency_generator.rb +30 -0
- data/lib/examples/hello_array.rb +48 -0
- data/lib/examples/hello_array2.rb +79 -0
- data/lib/examples/hello_array_eeprom.rb +59 -0
- data/lib/examples/hello_clock.rb +84 -0
- data/lib/examples/hello_eeprom.rb +51 -0
- data/lib/examples/hello_eeprom_lcdpa.rb +81 -0
- data/lib/examples/hello_format_print.rb +94 -0
- data/lib/examples/hello_lcd_charset.rb +75 -0
- data/lib/examples/hello_pa_lcd.rb +59 -0
- data/lib/examples/hello_servos.rb +88 -0
- data/lib/examples/hello_spectra_sound.rb +38 -0
- data/lib/examples/hello_world.rb +11 -0
- data/lib/examples/hello_xbee.rb +12 -0
- data/lib/examples/hysteresis_duel.rb +39 -0
- data/lib/examples/i2c_with_clock_chip.rb +124 -0
- data/lib/examples/midi_beat_box.rb +86 -0
- data/lib/examples/midi_scales.rb +94 -0
- data/lib/examples/motor_knob.rb +30 -0
- data/lib/examples/servo_buttons.rb +23 -0
- data/lib/examples/servo_calibrate_continuous.rb +92 -0
- data/lib/examples/servo_throttle.rb +40 -0
- data/lib/examples/software_serial.rb +10 -0
- data/lib/examples/sparkfun_lcd.rb +48 -0
- data/lib/examples/spectra_soft_pot.rb +34 -0
- data/lib/examples/times_method.rb +8 -0
- data/lib/examples/toggle.rb +10 -0
- data/lib/examples/twitter.rb +57 -0
- data/lib/examples/two_wire.rb +14 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.cpp +321 -0
- data/lib/libraries/AFSoftSerial/AFSoftSerial.h +61 -0
- data/lib/libraries/AFSoftSerial/keywords.txt +18 -0
- data/lib/libraries/AF_XPort/AF_XPort.cpp +166 -0
- data/lib/libraries/AF_XPort/AF_XPort.h +48 -0
- data/lib/libraries/DS1307/DS1307.cpp +162 -0
- data/lib/libraries/DS1307/DS1307.h +66 -0
- data/lib/libraries/DS1307/keywords.txt +18 -0
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp +144 -0
- data/lib/libraries/FrequencyTimer2/FrequencyTimer2.h +42 -0
- data/lib/libraries/FrequencyTimer2/keywords.txt +22 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.cpp +120 -0
- data/lib/libraries/I2CEEPROM/I2CEEPROM.h +70 -0
- data/lib/libraries/I2CEEPROM/keywords.txt +21 -0
- data/lib/libraries/LoopTimer/LoopTimer.cpp +35 -0
- data/lib/libraries/LoopTimer/LoopTimer.h +34 -0
- data/lib/libraries/LoopTimer/keywords.txt +27 -0
- data/lib/libraries/OneWire/OneWire.cpp +194 -0
- data/lib/libraries/OneWire/OneWire.h +63 -0
- data/lib/libraries/OneWire/keywords.txt +35 -0
- data/lib/libraries/OneWire/readme.txt +13 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp +296 -0
- data/lib/libraries/SWSerLCDpa/SWSerLCDpa.h +69 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp +311 -0
- data/lib/libraries/SWSerLCDsf/SWSerLCDsf.h +67 -0
- data/lib/libraries/Servo/Servo.cpp +192 -0
- data/lib/libraries/Servo/Servo.h +61 -0
- data/lib/libraries/Stepper/Stepper.cpp +220 -0
- data/lib/libraries/Stepper/Stepper.h +86 -0
- data/lib/libraries/Stepper/keywords.txt +28 -0
- data/lib/libraries/Wire/Wire.cpp +262 -0
- data/lib/libraries/Wire/Wire.h +67 -0
- data/lib/libraries/Wire/keywords.txt +31 -0
- data/lib/libraries/Wire/twi.h +57 -0
- data/lib/libraries/Wire/utility/twi.c +449 -0
- data/lib/libraries/Wire/utility/twi.h +57 -0
- data/lib/plugins/bitwise_ops.rb +54 -0
- data/lib/plugins/blink.rb +25 -0
- data/lib/plugins/blink_m.rb +356 -0
- data/lib/plugins/debounce.rb +138 -0
- data/lib/plugins/debug_output_to_lcd.rb +71 -0
- data/lib/plugins/hysteresis.rb +52 -0
- data/lib/plugins/input_output_state.rb +84 -0
- data/lib/plugins/lcd_padding.rb +58 -0
- data/lib/plugins/mem_test.rb +37 -0
- data/lib/plugins/midi.rb +60 -0
- data/lib/plugins/parallax_ping.rb +50 -0
- data/lib/plugins/servo_pulse.rb +31 -0
- data/lib/plugins/servo_setup.rb +86 -0
- data/lib/plugins/smoother.rb +54 -0
- data/lib/plugins/spark_fun_serial_lcd.rb +100 -0
- data/lib/plugins/spectra_symbol.rb +79 -0
- data/lib/plugins/twitter_connect.rb +145 -0
- data/lib/rad.rb +5 -0
- data/lib/rad/README.rdoc +5 -0
- data/lib/rad/arduino_plugin.rb +246 -0
- data/lib/rad/arduino_sketch.rb +627 -0
- data/lib/rad/generators/makefile/makefile.erb +243 -0
- data/lib/rad/generators/makefile/makefile.rb +38 -0
- data/lib/rad/hardware_library.rb +813 -0
- data/lib/rad/init.rb +14 -0
- data/lib/rad/progressbar.rb +236 -0
- data/lib/rad/rad_processor.rb +128 -0
- data/lib/rad/rad_rewriter.rb +94 -0
- data/lib/rad/rad_type_checker.rb +26 -0
- data/lib/rad/sim/arduino_sketch.rb +57 -0
- data/lib/rad/sketch_compiler.rb +47 -0
- data/lib/rad/tasks/build_and_make.rake +210 -0
- data/lib/rad/tasks/rad.rb +2 -0
- data/lib/rad/todo.txt +13 -0
- data/lib/rad/variable_processing.rb +153 -0
- data/lib/rad/version.rb +9 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/spec/examples/hello_world.rb +11 -0
- data/spec/examples/serial_motor.rb +12 -0
- data/spec/models/arduino_sketch_spec.rb +82 -0
- data/spec/models/sketch_compiler_spec.rb +96 -0
- data/spec/models/spec_helper.rb +2 -0
- data/spec/sim/hello_world_spec.rb +42 -0
- data/spec/spec.opts +1 -0
- data/test/test_array_processing.rb +179 -0
- data/test/test_plugin_loading.rb +151 -0
- data/test/test_translation_post_processing.rb +185 -0
- data/test/test_variable_processing.rb +238 -0
- data/website/examples/assembler_test.rb.html +73 -0
- data/website/examples/gps_reader.rb.html +39 -0
- data/website/examples/hello_world.rb.html +38 -0
- data/website/examples/serial_motor.rb.html +41 -0
- data/website/index.html +178 -0
- data/website/index.txt +64 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +169 -0
- data/website/template.rhtml +48 -0
- metadata +217 -0
data/lib/plugins/midi.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
class Midi < ArduinoPlugin
|
2
|
+
|
3
|
+
|
4
|
+
# reference
|
5
|
+
|
6
|
+
# To send MIDI, attach a MIDI out jack (female DIN-5) to Arduino.
|
7
|
+
# DIN-5 pinout is: _____
|
8
|
+
# pin 2 - Gnd / \
|
9
|
+
# pin 4 - 220 ohm resistor to +5V | 3 1 | Female MIDI jack
|
10
|
+
# pin 5 - Arduino D1 (TX) | 5 4 |
|
11
|
+
# all other pins - unconnected \__2__/
|
12
|
+
# Adapted from Tom Igoe's work at:
|
13
|
+
# http://itp.nyu.edu/physcomp/Labs/MIDIOutput
|
14
|
+
# And Tod E. Kurt <tod@todbot.com
|
15
|
+
# http://todbot.com/
|
16
|
+
#
|
17
|
+
# Created 25 October 2008
|
18
|
+
# copyleft 2008 jdbarnhart
|
19
|
+
# http://jdbarnhart.com/
|
20
|
+
|
21
|
+
void note_on(char cmd, int data1, char data2) {
|
22
|
+
Serial.print(cmd, BYTE);
|
23
|
+
Serial.print(data1, BYTE);
|
24
|
+
Serial.print(data2, BYTE);
|
25
|
+
}
|
26
|
+
|
27
|
+
void note_on(int channel, int note, int velocity) {
|
28
|
+
midi_msg( (0x90 | (channel)), note, velocity);
|
29
|
+
}
|
30
|
+
|
31
|
+
void note_on(long int& channel, long int& note, long int& velocity) {
|
32
|
+
midi_msg( (0x90 | (channel)), note, velocity);
|
33
|
+
}
|
34
|
+
|
35
|
+
void note_off(long int& channel, long int& note, long int& velocity) {
|
36
|
+
midi_msg( (0x90 | (channel)), note, velocity);
|
37
|
+
}
|
38
|
+
|
39
|
+
void note_off(byte channel, byte note, byte velocity) {
|
40
|
+
midi_msg( (0x90 | (channel)), note, velocity);
|
41
|
+
}
|
42
|
+
|
43
|
+
void play_note(long int& channel, long int& note, long int& velocity) {
|
44
|
+
midi_msg( (0x90 | (channel)), note, velocity);
|
45
|
+
delay(100);
|
46
|
+
midi_msg( (0x90 | (channel)), note, 0);
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
void midi_msg(byte cmd, byte data1, byte data2) {
|
52
|
+
digitalWrite(led(), 1); // indicate we're sending MIDI data
|
53
|
+
Serial.print(cmd, BYTE);
|
54
|
+
Serial.print(data1, BYTE);
|
55
|
+
Serial.print(data2, BYTE);
|
56
|
+
digitalWrite(led(), 0); // indicate we're sending MIDI data
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class ParallaxPing < ArduinoPlugin
|
2
|
+
|
3
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
4
|
+
# that may be added to the main setup method
|
5
|
+
# function prototypes not needed since we generate them automatically
|
6
|
+
|
7
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
8
|
+
|
9
|
+
# add to directives
|
10
|
+
# plugin_directives "#define EXAMPLE 10"
|
11
|
+
|
12
|
+
# add to external variables
|
13
|
+
# external_variables "int foo, bar"
|
14
|
+
|
15
|
+
# add the following to the setup method
|
16
|
+
# add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
|
17
|
+
|
18
|
+
# one or more methods may be added and prototypes are
|
19
|
+
|
20
|
+
# Methods for the Parallax Ping)) UltraSonic Distance Sensor.
|
21
|
+
#
|
22
|
+
# Example:
|
23
|
+
#
|
24
|
+
# class RangeFinder < ArduinoSketch
|
25
|
+
# serial_begin
|
26
|
+
#
|
27
|
+
# external_vars :sig_pin => 'int, 7'
|
28
|
+
#
|
29
|
+
# def loop
|
30
|
+
# serial_println(ping(sig_pin))
|
31
|
+
# delay(200)
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
|
35
|
+
# Triggers a pulse and returns the delay in microseconds for the echo.
|
36
|
+
int ping(int pin) {
|
37
|
+
pinMode(pin, OUTPUT);
|
38
|
+
|
39
|
+
digitalWrite(pin, LOW);
|
40
|
+
delayMicroseconds(2);
|
41
|
+
digitalWrite(pin, HIGH);
|
42
|
+
delayMicroseconds(5);
|
43
|
+
digitalWrite(pin, LOW);
|
44
|
+
|
45
|
+
pinMode(pin, INPUT);
|
46
|
+
|
47
|
+
return pulseIn(pin, HIGH);
|
48
|
+
}
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ServoPulse < ArduinoPlugin
|
2
|
+
|
3
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
4
|
+
# that may be added to the main setup method
|
5
|
+
# function prototypes not needed since we generate them automatically
|
6
|
+
|
7
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
8
|
+
|
9
|
+
# add to directives
|
10
|
+
#plugin_directives "#define EXAMPLE 10"
|
11
|
+
|
12
|
+
# add to external variables
|
13
|
+
# external_variables "int foo, bar"
|
14
|
+
|
15
|
+
# add the following to the setup method
|
16
|
+
# add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
|
17
|
+
|
18
|
+
# one or more methods may be added and prototypes are generated automatically with rake make:upload
|
19
|
+
|
20
|
+
# call pulse(us) to pulse a servo
|
21
|
+
# this can be eliminate since we have an identical pulse_servo in servo_setup
|
22
|
+
|
23
|
+
void pulse(int pin, int us) {
|
24
|
+
digitalWrite( pin, HIGH );
|
25
|
+
delayMicroseconds( us );
|
26
|
+
digitalWrite( pin, LOW );
|
27
|
+
serv[pin].pulseWidth = us;
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
class ServoSetup < ArduinoPlugin
|
2
|
+
|
3
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
4
|
+
# that may be added to the main setup method
|
5
|
+
# function prototypes not needed since we generate them automatically
|
6
|
+
|
7
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
8
|
+
|
9
|
+
# add to directives
|
10
|
+
#plugin_directives "#define EXAMPLE 10"
|
11
|
+
|
12
|
+
# add to external variables
|
13
|
+
# external_variables "int foo, bar"
|
14
|
+
|
15
|
+
# add the following to the setup method
|
16
|
+
# add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
|
17
|
+
|
18
|
+
# one or more methods may be added and prototypes are generated automatically with rake make:upload
|
19
|
+
|
20
|
+
|
21
|
+
# one line servo control
|
22
|
+
#
|
23
|
+
# move_servo my_servo, amount
|
24
|
+
#
|
25
|
+
# example:
|
26
|
+
#
|
27
|
+
# class MoveServo < ArduinoSketch
|
28
|
+
#
|
29
|
+
# external_vars :sensor_position => "int, 0", :servo_amount => "int, 0"
|
30
|
+
#
|
31
|
+
# output_pin 4, :as => :my_servo, :min => 700, :max => 2200
|
32
|
+
# input_pin 1, :as => :sensor
|
33
|
+
# def loop
|
34
|
+
# sensor_position = analogRead(sensor)
|
35
|
+
# servo_amount = (sensor_position*2 + 500)
|
36
|
+
# move_servo my_servo, servo_amount
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
#
|
41
|
+
# supports multiple servos by storing variables in the serv struc array that is constructed when
|
42
|
+
# the :min and :max options are added to the output_pin method
|
43
|
+
|
44
|
+
|
45
|
+
add_servo_struct
|
46
|
+
|
47
|
+
void move_servo(int servo_num, int pulse_width)
|
48
|
+
{
|
49
|
+
struct servo servo_name = serv[servo_num];
|
50
|
+
|
51
|
+
int pw = pulse_width;
|
52
|
+
/* apply the servo limits */
|
53
|
+
if (pw > servo_name.max)
|
54
|
+
pw = servo_name.max;
|
55
|
+
if (pw < servo_name.min)
|
56
|
+
pw = servo_name.min;
|
57
|
+
|
58
|
+
if (millis() - servo_name.lastPulse >= servo_name.refreshTime)
|
59
|
+
{
|
60
|
+
pulse_servo(servo_name.pin, pw);
|
61
|
+
servo_name.lastPulse = millis();
|
62
|
+
// if (find_total_loop_time() < 10)
|
63
|
+
// for debug:
|
64
|
+
// digitalWrite( 5, HIGH );
|
65
|
+
// 18 seems optimal, but we should let the users adjust with a servo option
|
66
|
+
delay(18);
|
67
|
+
}
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
void pulse_servo(int pin, int us) {
|
72
|
+
digitalWrite( pin, HIGH );
|
73
|
+
// pulseWidth
|
74
|
+
delayMicroseconds( us );
|
75
|
+
digitalWrite( pin, LOW );
|
76
|
+
serv[pin].pulseWidth = us;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Smoother < ArduinoPlugin
|
2
|
+
|
3
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
4
|
+
# that may be added to the main setup method
|
5
|
+
# function prototypes not needed since we generate them automatically
|
6
|
+
|
7
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
8
|
+
|
9
|
+
# add to directives
|
10
|
+
plugin_directives "#define ARY_SIZE 10"
|
11
|
+
|
12
|
+
# add to external variables
|
13
|
+
external_variables "int *cur, *scan, *start, *end;", "int sm_ary[ARY_SIZE];", "int last_reading = 0;"
|
14
|
+
|
15
|
+
# add the following to the setup method
|
16
|
+
add_to_setup "scan = &sm_ary[0];", "cur = &sm_ary[0];", "start = &sm_ary[0];", "end = &sm_ary[ARY_SIZE-1];"
|
17
|
+
|
18
|
+
# add an element to the array and return the average
|
19
|
+
|
20
|
+
int add_hysteresis(int reading, int hysteresis)
|
21
|
+
{
|
22
|
+
if ( ((reading - last_reading) > hysteresis) || ((last_reading - reading) > hysteresis)) {
|
23
|
+
|
24
|
+
last_reading = reading;
|
25
|
+
return reading;
|
26
|
+
}
|
27
|
+
else
|
28
|
+
return last_reading;
|
29
|
+
}
|
30
|
+
|
31
|
+
int smooth_average(int reading)
|
32
|
+
{
|
33
|
+
int sum, cnt;
|
34
|
+
cnt = 0;
|
35
|
+
sum = 0;
|
36
|
+
*cur = reading;
|
37
|
+
cur++;
|
38
|
+
for (scan = &sm_ary[0]; scan < &sm_ary[ARY_SIZE-1]; cnt++, scan++)
|
39
|
+
sum += *scan;
|
40
|
+
ptr_reset();
|
41
|
+
return sum/cnt;
|
42
|
+
}
|
43
|
+
|
44
|
+
void ptr_reset(void)
|
45
|
+
{
|
46
|
+
if (cur == end)
|
47
|
+
{
|
48
|
+
cur = &sm_ary[0];
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
class SparkFunSerialLcd < ArduinoPlugin
|
2
|
+
|
3
|
+
# RAD plugins are c methods, directives, external variables and assignments and calls
|
4
|
+
# that may be added to the main setup method
|
5
|
+
# function prototypes not needed since we generate them automatically
|
6
|
+
|
7
|
+
# directives, external variables and setup assignments and calls can be added rails style (not c style)
|
8
|
+
# hack from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1209050315
|
9
|
+
|
10
|
+
plugin_directives "#undef int", "#include <stdio.h>", "char _str[32];", "#define writeln(...) sprintf(_str, __VA_ARGS__); Serial.println(_str)"
|
11
|
+
# add to directives
|
12
|
+
#plugin_directives "#define EXAMPLE 10"
|
13
|
+
|
14
|
+
# add to external variables
|
15
|
+
external_variables "char status_message[40] = \"very cool\"", "char* msg[40]"
|
16
|
+
|
17
|
+
# add the following to the setup method
|
18
|
+
# add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
|
19
|
+
|
20
|
+
# one or more methods may be added and prototypes are generated automatically with rake make:upload
|
21
|
+
|
22
|
+
# methods for sparkfun serial lcd SerLCD v2.5
|
23
|
+
|
24
|
+
void print_sensor_position_plus(int reading){
|
25
|
+
|
26
|
+
|
27
|
+
/* writeln("sensor: %d ", reading); */
|
28
|
+
Serial.print("sensor: ");
|
29
|
+
Serial.print(reading);
|
30
|
+
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
void print_sensor_position(long pos){
|
35
|
+
Serial.print(pos);
|
36
|
+
}
|
37
|
+
|
38
|
+
void lcd_first_line(){ //puts the cursor at line 0 char 0.
|
39
|
+
Serial.print(0xFE, BYTE); //command flag
|
40
|
+
Serial.print(128, BYTE); //position
|
41
|
+
}
|
42
|
+
|
43
|
+
void lcd_second_line(){ //puts the cursor at line 0 char 0.
|
44
|
+
Serial.print(0xFE, BYTE); //command flag
|
45
|
+
Serial.print(192, BYTE); //position
|
46
|
+
}
|
47
|
+
|
48
|
+
void selectLineOne(){ //puts the cursor at line 0 char 0.
|
49
|
+
Serial.print(0xFE, BYTE); //command flag
|
50
|
+
Serial.print(128, BYTE); //position
|
51
|
+
}
|
52
|
+
void selectLineTwo(){ //puts the cursor at line 0 char 0.
|
53
|
+
Serial.print(0xFE, BYTE); //command flag
|
54
|
+
Serial.print(192, BYTE); //position
|
55
|
+
}
|
56
|
+
void clearLCD(){
|
57
|
+
Serial.print(0xFE, BYTE); //command flag
|
58
|
+
Serial.print(0x01, BYTE); //clear command.
|
59
|
+
}
|
60
|
+
void backlightOn(){ //turns on the backlight
|
61
|
+
Serial.print(0x7C, BYTE); //command flag for backlight stuff
|
62
|
+
Serial.print(157, BYTE); //light level.
|
63
|
+
}
|
64
|
+
|
65
|
+
void set_backlight_level(int level){ //turns on the backlight
|
66
|
+
if (level > 29)
|
67
|
+
level = 29;
|
68
|
+
Serial.print(0x7C, BYTE); //command flag for backlight stuff
|
69
|
+
Serial.print(157 + level, BYTE); //light level.
|
70
|
+
}
|
71
|
+
|
72
|
+
void toggle_backlight(){ //turns off the backlight
|
73
|
+
Serial.print(0x7C, BYTE); //command flag for backlight stuff
|
74
|
+
Serial.print("|"); //light level for off.
|
75
|
+
Serial.print(1);
|
76
|
+
}
|
77
|
+
|
78
|
+
void set_splash(){
|
79
|
+
selectLineOne();
|
80
|
+
Serial.print(" Ruby + Auduino");
|
81
|
+
selectLineTwo();
|
82
|
+
Serial.print(" RAD 0.2.4+ ");
|
83
|
+
Serial.print(0x7C, BYTE); // decimal 124, command flag for backlight stuff
|
84
|
+
Serial.print(10, BYTE);
|
85
|
+
}
|
86
|
+
|
87
|
+
void backlightOff(){ //turns off the backlight
|
88
|
+
Serial.print(0x7C, BYTE); // decimal 124, command flag for backlight stuff
|
89
|
+
Serial.print(128, BYTE); //light level for off.
|
90
|
+
}
|
91
|
+
void serCommand(){ // decimal 254, a general function to call the command flag for issuing all other commands
|
92
|
+
Serial.print(0xFE, BYTE);
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class SpectraSymbol < ArduinoPlugin
|
2
|
+
|
3
|
+
# jdbarnhart
|
4
|
+
# 20080729
|
5
|
+
#
|
6
|
+
# crazy experiment in progress
|
7
|
+
# purpose
|
8
|
+
#
|
9
|
+
# retain last reading after finger is removed from spectrasymbol
|
10
|
+
# soft pot
|
11
|
+
#
|
12
|
+
# use
|
13
|
+
# two steps
|
14
|
+
#
|
15
|
+
# one
|
16
|
+
# declare :device => :sensor
|
17
|
+
# example:
|
18
|
+
# input_pin 1, :as => :sensor_one, :device => :spectra
|
19
|
+
#
|
20
|
+
# two
|
21
|
+
# instead of:
|
22
|
+
# my_lcd.print analogRead sensor_two
|
23
|
+
# use soft_lock
|
24
|
+
# my_lcd.print sensor_one.spectra_lock
|
25
|
+
#
|
26
|
+
#
|
27
|
+
# notes:
|
28
|
+
# experimental settings for 100mm spectrasymbol
|
29
|
+
#
|
30
|
+
# hysteresis is set at 5
|
31
|
+
# amount of sensor drop is set to 3
|
32
|
+
# delay time (dtime) is 4
|
33
|
+
# cutoff set to 10
|
34
|
+
#
|
35
|
+
int soft_lock(int pin)
|
36
|
+
|
37
|
+
{
|
38
|
+
int hyst = 5;
|
39
|
+
int drop = 3;
|
40
|
+
int dtime = 4;
|
41
|
+
int cutoff = 10;
|
42
|
+
int read;
|
43
|
+
int r1;
|
44
|
+
int r2;
|
45
|
+
int r3;
|
46
|
+
unsigned int i;
|
47
|
+
read = analogRead(pin)/4;
|
48
|
+
delay(dtime);
|
49
|
+
r1 = analogRead(pin)/4;
|
50
|
+
delay(dtime);
|
51
|
+
r2 = analogRead(pin)/4;
|
52
|
+
delay(dtime);
|
53
|
+
r3 = analogRead(pin)/4;
|
54
|
+
delay(dtime);
|
55
|
+
for (i = 0; i < (int) (sizeof(spec) / sizeof(spec[0])); i++) {
|
56
|
+
if (pin == spec[i].pin) {
|
57
|
+
if (((r3 - r2) > drop) && ((r2 - r1) > drop) && ((r1 - read) > drop))
|
58
|
+
return spec[i].state - 10;
|
59
|
+
else
|
60
|
+
{
|
61
|
+
if (read < cutoff)
|
62
|
+
return spec[i].state - 10;
|
63
|
+
else
|
64
|
+
{
|
65
|
+
if (((read - spec[i].state) > hyst ) || ((spec[i].state - read) > hyst )) {
|
66
|
+
spec[i].state = read;
|
67
|
+
return spec[i].state - 10;
|
68
|
+
}
|
69
|
+
else
|
70
|
+
return spec[i].state - 10;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
end
|