Last active
April 14, 2017 05:07
-
-
Save rockos/cfddbf7fc4f80d2a723f1768f72c42f2 to your computer and use it in GitHub Desktop.
kidslab201704_arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xml xmlns="http://www.w3.org/1999/xhtml"><block type="variables_set" id="557" inline="true" x="88" y="-212"><field name="TYPE">Boolean</field><field name="VAR">item</field><value name="VALUE"><block type="inout_digital_read" id="473"><field name="PIN">2</field><field name="INPUT_MODE">INPUT</field></block></value><next><block type="controls_if" id="484" inline="false"><value name="IF0"><block type="logic_compare" id="315" inline="true"><field name="OP">EQ</field><value name="A"><block type="variables_get" id="318"><field name="TYPE">Number</field><field name="VAR">item</field></block></value><value name="B"><block type="inout_highlow" id="464"><field name="BOOL">LOW</field></block></value></block></value><statement name="DO0"><block type="tone" id="478"><field name="PIN">10</field><field name="FREQ">262</field><next><block type="delay_custom" id="579" inline="false"><value name="DELAY_TIME"><block type="math_number" id="580"><field name="NUM">300</field></block></value><next><block type="tone" id="581"><field name="PIN">10</field><field name="FREQ">294</field><next><block type="delay_custom" id="582" inline="false"><value name="DELAY_TIME"><block type="math_number" id="583"><field name="NUM">300</field></block></value><next><block type="tone" id="584"><field name="PIN">10</field><field name="FREQ">330</field><next><block type="delay_custom" id="585" inline="false"><value name="DELAY_TIME"><block type="math_number" id="586"><field name="NUM">300</field></block></value><next><block type="tone" id="599"><field name="PIN">10</field><field name="FREQ">349</field><next><block type="delay_custom" id="597" inline="false"><value name="DELAY_TIME"><block type="math_number" id="598"><field name="NUM">300</field></block></value><next><block type="tone" id="600"><field name="PIN">10</field><field name="FREQ">392</field><next><block type="delay_custom" id="601" inline="false"><value name="DELAY_TIME"><block type="math_number" id="602"><field name="NUM">300</field></block></value><next><block type="tone" id="603"><field name="PIN">10</field><field name="FREQ">440</field><next><block type="delay_custom" id="604" inline="false"><value name="DELAY_TIME"><block type="math_number" id="605"><field name="NUM">300</field></block></value><next><block type="tone" id="606"><field name="PIN">10</field><field name="FREQ">494</field><next><block type="delay_custom" id="607" inline="false"><value name="DELAY_TIME"><block type="math_number" id="608"><field name="NUM">300</field></block></value><next><block type="tone" id="609"><field name="PIN">10</field><field name="FREQ">523</field><next><block type="delay_custom" id="610" inline="false"><value name="DELAY_TIME"><block type="math_number" id="611"><field name="NUM">1000</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement><next><block type="inout_custom_digital_write" id="594" inline="true"><value name="PIN"><block type="inout_digitalpin" id="595"><field name="PIN">10</field></block></value><value name="STAT"><block type="inout_highlow" id="596"><field name="BOOL">LOW</field></block></value></block></next></block></next></block><block type="custom_tone" id="620" inline="true" x="513" y="-87"><field name="PIN">0</field><field name="DURATION">300</field><value name="FREQ"><block type="math_number" id="621"><field name="NUM">255</field></block></value></block></xml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xml xmlns="http://www.w3.org/1999/xhtml"><block type="variables_set" id="28" inline="true" x="38" y="38"><field name="TYPE">Number</field><field name="VAR">blightness</field><value name="VALUE"><block type="math_number" id="29"><field name="NUM">0</field></block></value><next><block type="controls_while" id="30" inline="false"><value name="BOOL"><block type="logic_compare" id="31" inline="true"><field name="OP">LTE</field><value name="A"><block type="variables_get" id="32"><field name="TYPE">Number</field><field name="VAR">blightness</field></block></value><value name="B"><block type="math_number" id="33"><field name="NUM">130</field></block></value></block></value><statement name="DO"><block type="variables_set" id="34" inline="true"><field name="TYPE">Number</field><field name="VAR">blightness</field><value name="VALUE"><block type="math_arithmetic" id="35" inline="true"><field name="OP">ADD</field><value name="A"><block type="variables_get" id="36"><field name="TYPE">Number</field><field name="VAR">blightness</field></block></value><value name="B"><block type="math_number" id="37"><field name="NUM">3</field></block></value></block></value><next><block type="inout_analog_write" id="38" inline="true"><field name="PIN">10</field><value name="NUM"><block type="variables_get" id="39"><field name="TYPE">Number</field><field name="VAR">blightness</field></block></value><next><block type="delay_custom" id="40" inline="false"><value name="DELAY_TIME"><block type="math_number" id="41"><field name="NUM">50</field></block></value></block></next></block></next></block></statement><next><block type="delay_custom" id="42" inline="false"><value name="DELAY_TIME"><block type="math_number" id="43"><field name="NUM">1000</field></block></value><next><block type="inout_analog_write" id="44" inline="true"><field name="PIN">10</field><value name="NUM"><block type="math_number" id="45"><field name="NUM">0</field></block></value></block></next></block></next></block></next></block></xml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int trig_pin = 2; | |
int echo_pin = 3; | |
int dist = 0; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(trig_pin, OUTPUT); | |
pinMode(echo_pin, INPUT); | |
Serial.begin( 9600 ); | |
} | |
long Sonic_Timing(){ | |
digitalWrite(trig_pin, LOW); | |
delayMicroseconds(2); | |
digitalWrite(trig_pin, HIGH); | |
delayMicroseconds(20); | |
digitalWrite(trig_pin, LOW); | |
long duration = pulseIn(echo_pin,HIGH); | |
return duration; | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
if ( Serial.available() > 0 ) { | |
Serial.read(); | |
dist = Sonic_Timing()/29/2; | |
Serial.print( dist, 4 ); | |
Serial.print( "\n" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment