{"id":192,"date":"2017-03-01T19:12:36","date_gmt":"2017-03-01T19:12:36","guid":{"rendered":"http:\/\/ulm.taddug.com\/?p=192"},"modified":"2017-03-13T20:24:41","modified_gmt":"2017-03-13T20:24:41","slug":"soft-potentiometer-sketch","status":"publish","type":"post","link":"https:\/\/ulm.taddug.com\/index.php\/2017\/03\/01\/soft-potentiometer-sketch\/","title":{"rendered":"Soft Potentiometer Sketch"},"content":{"rendered":"<p>\/\/ SR will be .25 seconds<\/p>\n<p>const int sr = 250; \/\/ sample rate in ms??<br \/>\n\/\/ const int setdist = 256; \/\/ Distance to travel per sample<br \/>\nconst int le = 40; \/\/ Low end of travel<br \/>\nconst int he = 100; \/\/ High end of travel<br \/>\nint dir = 1; \/\/ 1 is clockwise -1 is counterclockwise<br \/>\nconst int SENSOR_PIN = 0; \/\/ Pin for ribbon<br \/>\nconst int LED_PIN = 12; \/\/ LED pin location<br \/>\n\/\/ const int forgiveness = 2; \/\/ 2 samples forgiveness<br \/>\nbool flowing = false;<br \/>\nbool prevFlow = false;<br \/>\nint prevRead = 0;<\/p>\n<p>void setup() {<br \/>\n\/\/ put your setup code here, to run once:<br \/>\nSerial.begin(9600);<br \/>\npinMode( LED_PIN, OUTPUT );<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n\/\/ put your main code here, to run repeatedly:<br \/>\nint sensorVal = analogRead( SENSOR_PIN );<br \/>\nint sensDelta = sensorVal &#8211; prevRead;<\/p>\n<p>prevRead = sensorVal;<\/p>\n<p>if ( sensDelta != 0 ) {<br \/>\n\/\/Serial.print(&#8220;Val: &#8220;);<br \/>\n\/\/Serial.println( sensorVal );<br \/>\nSerial.print(&#8220;Delta: &#8220;);<br \/>\nSerial.println( sensDelta );<\/p>\n<p>if ( ( sensDelta &gt; le ) &amp;&amp; ( sensDelta &lt; he ) ) {<br \/>\nflowing = true;<br \/>\nSerial.println( &#8220;Flow detected&#8221; );<br \/>\n}<\/p>\n<p>if ( !( ( prevFlow == true ) || ( flowing == true ) ) ) {<br \/>\nSerial.println( &#8220;oops&#8221; );<br \/>\ndigitalWrite( LED_PIN, LOW );<br \/>\n}<br \/>\nelse {<br \/>\ndigitalWrite( LED_PIN, HIGH );<br \/>\n}<\/p>\n<p>prevFlow = flowing;<br \/>\nflowing = false;<br \/>\n}<br \/>\nelse {<br \/>\ndigitalWrite( LED_PIN, LOW );<br \/>\n}<\/p>\n<p>delay( sr );<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ SR will be .25 seconds const int sr = 250; \/\/ sample [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":262,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[],"class_list":["post-192","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-research","category-residency"],"_links":{"self":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts\/192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/comments?post=192"}],"version-history":[{"count":1,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts\/192\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts\/192\/revisions\/193"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/media\/262"}],"wp:attachment":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/media?parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/categories?post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/tags?post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}