{"id":117,"date":"2013-02-12T19:29:29","date_gmt":"2013-02-12T19:29:29","guid":{"rendered":"http:\/\/richardalbritton.wordpress.com\/?p=50"},"modified":"2015-01-16T00:18:24","modified_gmt":"2015-01-16T00:18:24","slug":"electric-imp-project","status":"publish","type":"post","link":"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/","title":{"rendered":"Electric Imp project."},"content":{"rendered":"<p>I am working on using the Electric Imp I got from Adafruit to make a WiFi enabled\u00a0Emoticon\u00a0avatar.\u00a0Basically\u00a0it will\u00a0receive\u00a0code from a website and display the icon for that code on a small 8&#215;8 LED matrix\u00a0accompanied\u00a0by a notification\u00a0sound. This will also provide feedback through a button on the\u00a0avatar\u00a0to\u00a0acknowledge\u00a0the emoticon, and a motion detector to tell when\u00a0someone\u00a0is near the\u00a0avatar.<\/p>\n<p><!--more--><\/p>\n<p>So far I have gotten the Imp to\u00a0receive\u00a0data from a webpage and turn LEDs on or off from three\u00a0independent\u00a0I\/O pins. The LEDs are red, green, and blue so they make\u00a0different\u00a0colors depending on which ones are on.<br \/>\nHere is the code I am using to do this.<\/p>\n<p>Squirrel code:<\/p>\n<pre class=\"lang:c decode:true\">\/\/ Register with the server\r\n\/\/ April with brightness-controlled LED\r\n\r\nhardware.pin1.configure(PWM_OUT, 1.0\/500.0, 1.0);\r\nhardware.pin2.configure(PWM_OUT, 1.0\/500.0, 1.0);\r\nhardware.pin5.configure(PWM_OUT, 1.0\/500.0, 1.0);\r\n\r\nclass TableIn extends InputPort\r\n{\r\n\/\/name = \"LED Brightness\"\r\n\/\/type = \"number\"\r\n\r\nfunction set(v) {\r\n\/\/ since pin 9 is configured for PWM, we can set the duty cycle with pin.write()\r\n\/\/ write a floating point number between 0.0 and 1.0, where 1.0 = 100% duty cycle\r\nhardware.pin1.write(v.red);\r\nhardware.pin2.write(v.green);\r\nhardware.pin5.write(v.blue);\r\nserver.log(\"v.red: \"+v.red+\" v.green: \"+v.green+\" v.blue: \"+v.blue);\r\n}\r\n}\r\n\r\n\/\/ Variable to represent LED state\r\nledState &lt;- 0;\r\n\r\n\/\/ blink function called every 100ms\r\nfunction blink()\r\n{\r\n\/\/ Change state\r\nledState = ledState?0:1;\r\n\r\n\/\/ Reflect state to the pin\r\nhardware.pin8.write(ledState);\r\n\r\n\/\/ Schedule the next state change\r\nimp.wakeup(0.1, blink);\r\n}\r\n\r\n\/\/ Configure pin 9 as an open drain output with internal pull up\r\nhardware.pin8.configure(DIGITAL_OUT_OD_PULLUP);\r\n\r\nserver.log(\"Brightness Controller Started\");\r\nimp.configure(\"April Brightness Controller\", [ TableIn() ], []);\r\n\/\/blink();\r\nserver.sleepfor(30);<\/pre>\n<p>HTML Form:<\/p>\n<p><span style=\"color: #3366ff;\">Note: You will need to replace the\u00a0&#8220;https:\/\/api.electricimp.com\/v1\/&#8230;use.your.own.address&#8230;&#8221; with the URL from the HTTP IN node in the Imp Planner.<\/span><\/p>\n<pre class=\"lang:default decode:true\">&lt;html&gt;&lt;head&gt;&lt;script&gt;\r\nfunction sendForm(form)\r\n{\r\n\/\/ Construct the JSON string in form.value\r\n\/\/ x is a string ('cos of the quotes)\r\n\/\/ y is an integer ('cos of no quotes)\r\nform.value.value = \"{ \"red\": \" + form.red.value + \", \"green\": \" + form.green.value + \", \"blue\": \" + form.blue.value + \" }\"\r\nform.submit();\r\n}\r\n&lt;\/script&gt;&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;table width=\"200\" border=\"1\"&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;Off&lt;\/td&gt;\r\n&lt;td&gt;&lt;form action=\"https:\/\/api.electricimp.com\/v1\/...use.your.own.address...\" method=\"post\" target=\"stat\"&gt;\r\n&lt;input type=\"hidden\" name=\"value\"&gt;\r\n&lt;input type=\"hidden\" name=\"red\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"green\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"blue\" value=1&gt;\r\n&lt;input type=\"button\" value=\"ON\" onclick=\"sendForm(this.form);\" \/&gt;\r\n&lt;\/form&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;Red&lt;\/td&gt;\r\n&lt;td&gt;&lt;form action=\"https:\/\/api.electricimp.com\/v1\/...use.your.own.address...\" method=\"post\" target=\"stat\"&gt;\r\n&lt;input type=\"hidden\" name=\"value\"&gt;\r\n&lt;input type=\"hidden\" name=\"red\" value=0&gt;\r\n&lt;input type=\"hidden\" name=\"green\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"blue\" value=1&gt;\r\n&lt;input type=\"button\" value=\"ON\" onclick=\"sendForm(this.form);\" \/&gt;\r\n&lt;\/form&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;Orange&lt;\/td&gt;\r\n&lt;td&gt;&lt;form action=\"https:\/\/api.electricimp.com\/v1\/...use.your.own.address...\" method=\"post\" target=\"stat\"&gt;\r\n&lt;input type=\"hidden\" name=\"value\"&gt;\r\n&lt;input type=\"hidden\" name=\"red\" value=0&gt;\r\n&lt;input type=\"hidden\" name=\"green\" value=0&gt;\r\n&lt;input type=\"hidden\" name=\"blue\" value=1&gt;\r\n&lt;input type=\"button\" value=\"ON\" onclick=\"sendForm(this.form);\" \/&gt;\r\n&lt;\/form&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;green&lt;\/td&gt;\r\n&lt;td&gt;&lt;form action=\"https:\/\/api.electricimp.com\/v1\/...use.your.own.address...\" method=\"post\" target=\"stat\"&gt;\r\n&lt;input type=\"hidden\" name=\"value\"&gt;\r\n&lt;input type=\"hidden\" name=\"red\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"green\" value=0&gt;\r\n&lt;input type=\"hidden\" name=\"blue\" value=1&gt;\r\n&lt;input type=\"button\" value=\"ON\" onclick=\"sendForm(this.form);\" \/&gt;\r\n&lt;\/form&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;light blue&lt;\/td&gt;\r\n&lt;td&gt;&lt;form action=\"https:\/\/api.electricimp.com\/v1\/...use.your.own.address...\" method=\"post\" target=\"stat\"&gt;\r\n&lt;input type=\"hidden\" name=\"value\"&gt;\r\n&lt;input type=\"hidden\" name=\"red\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"green\" value=0&gt;\r\n&lt;input type=\"hidden\" name=\"blue\" value=0&gt;\r\n&lt;input type=\"button\" value=\"ON\" onclick=\"sendForm(this.form);\" \/&gt;\r\n&lt;\/form&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;blue&lt;\/td&gt;\r\n&lt;td&gt;&lt;form action=\"https:\/\/api.electricimp.com\/v1\/...use.your.own.address...\" method=\"post\" target=\"stat\"&gt;\r\n&lt;input type=\"hidden\" name=\"value\"&gt;\r\n&lt;input type=\"hidden\" name=\"red\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"green\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"blue\" value=0&gt;\r\n&lt;input type=\"button\" value=\"ON\" onclick=\"sendForm(this.form);\" \/&gt;\r\n&lt;\/form&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td&gt;perple&lt;\/td&gt;\r\n&lt;td&gt;&lt;form action=\"https:\/\/api.electricimp.com\/v1\/...use.your.own.address...\" method=\"post\" target=\"stat\"&gt;\r\n&lt;input type=\"hidden\" name=\"value\"&gt;\r\n&lt;input type=\"hidden\" name=\"red\" value=0&gt;\r\n&lt;input type=\"hidden\" name=\"green\" value=1&gt;\r\n&lt;input type=\"hidden\" name=\"blue\" value=0&gt;\r\n&lt;input type=\"button\" value=\"ON\" onclick=\"sendForm(this.form);\" \/&gt;\r\n&lt;\/form&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n&lt;iframe src=\"\" name=\"stat\"&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>This code is based on the example found <a href=\"http:\/\/devwiki.electricimp.com\/doku.php?id=httpapi\" target=\"_blank\">here<\/a>.<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/?share=email\" target=\"_blank\" title=\"Click to email this to a friend\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-117\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-117\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>I am working on using the Electric Imp I got from Adafruit to make a WiFi enabled\u00a0Emoticon\u00a0avatar.\u00a0Basically\u00a0it will\u00a0receive\u00a0code from a website and display the icon for that code on a small 8&#215;8 LED matrix\u00a0accompanied\u00a0by a notification\u00a0sound. This will also provide feedback through a button on the\u00a0avatar\u00a0to\u00a0acknowledge\u00a0the emoticon, and a motion detector to tell when\u00a0someone\u00a0is near &hellip; <a href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Electric Imp project.<\/span><\/a><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-print\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-print sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/\" target=\"_blank\" title=\"Click to print\"><span>Print<\/span><\/a><\/li><li class=\"share-email\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-email sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/?share=email\" target=\"_blank\" title=\"Click to email this to a friend\"><span>Email<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-117\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/?share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-117\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/www.richa1.com\/RichardAlbritton\/electric-imp-project\/?share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":726,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[62,64],"tags":[16,18,20,21],"jetpack_featured_media_url":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-content\/uploads\/2013\/02\/imgres.png","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5AhH6-1T","_links":{"self":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/117"}],"collection":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":2,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/posts\/117\/revisions\/727"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/media\/726"}],"wp:attachment":[{"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.richa1.com\/RichardAlbritton\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}