[{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eBlockly has been slowly worming it's way into Adafruit IO, with a first edition replicating the old Action forms.\u003cbr\u003eNow the latest release brings the wealth of features we've been dreaming of, allowing great complexity!\u003c/p\u003e\n\u003cp\u003eWill you be the first to bring down the house of cards/servers? Let us know in the forums if you do (or run into other issues)! Let's start off with\u0026nbsp;\u003cspan style=\"text-decoration: underline;\"\u003esomething simple\u003c/span\u003e, how to subtract one from a feed value (as a countdown)...\u003c/p\u003e\n\u003cp\u003eWe'll explore a quick yet complex multi-action example, changing LED colour based on air quality, and additionally a Utility Light mode using the onboard button to request 30seconds of Bright White Light (useful in a kitchen).\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/770/original/image.png?1746048276","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch1\u003eSetup a Wippersnapper device\u003c/h1\u003e\n\u003cp\u003eAdafruit IO has a devices page, which shows the special \"Wippersnapper\" devices, these run the arduino firmware that allows wifi connected boards to easily connect and configure components (inputs/outputs/sensors) with no code. Each component then has associated feeds for interacting with, so using the on board button becomes child's play.\u003c/p\u003e\n\u003cp\u003eInstall wippersnapper, you're best off finding the learn guide for your board and then locate the Wippersnapper pages. Alternatively there\u003ca href=\"https://learn.adafruit.com/quickstart-adafruit-io-wippersnapper\"\u003e is a quick start guide\u003c/a\u003e, or just do the usual hacky thing and have a go with no prior knowledge...\u003c/p\u003e\n\u003cp\u003eVisit this link (\u003ca href=\"https://io.adafruit.com/devices/new\"\u003ehttps://io.adafruit.com/devices/new\u003c/a\u003e) when signed in to be taken to the New Device setup page, then select your board and follow the onscreen instructions. \u003cbr\u003e\u003cem\u003e(You need an IO page open when the board first connects to accept the registration request).\u003c/em\u003e\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/769/original/image.png?1746047395","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eOnce setup you can visit the devices page and select the device to be taken to the Device overview page. You'll see there are no components configured, so use the\u0026nbsp;\u003cstrong\u003eAuto Config\u003c/strong\u003e button followed by the \u003cstrong\u003eMagic Config\u003c/strong\u003e option to easily add the on-board components. Most boards have at least an LED/NeoPixel, and a user button (but not all).\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/768/original/image.png?1746047313","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eAs shown in the previous image, you can see I have already added the boot button and pin D32 (NeoPixel strip), so warnings are displayed when revisiting the Magic Config page suggesting that those components won't import successfully (unselecting the two components means the automatic configuration of the remaining components can continue).\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch1\u003eActions\u003c/h1\u003e\n\u003cp\u003eFirst things first, you need a sensor or something supplying fresh data. Heck these days you can even use the Weatherkit powerup block to feed regularly updated weather data in to a feed using a Schedule trigger block.\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eFor now I've got an SCD40 Carbon Dioxide (CO2) sensor connected, reporting at 5second intervals (good for demos).\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"product","content":"https://www.adafruit.com/product/5187","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eNext we need to goto the Feeds page, and create a new feed called \u003ccode\u003ecounter\u003c/code\u003e which we'll use in the actions.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eNow we can create the Actions, but first be aware that there is currently a cooldown period of 5seconds (meaning actions won't trigger more frequently than 5seconds or 0.2Hz). As a result, I've split my complex action into multiple actions, that way each time the CO2 data arrives it won't affect the cooldown of the Button feed being listened too (the CO2 arriving would mean all other triggers were ignored for 5seconds).\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"alert","content":"\u003cp\u003eActions have a cooldown and won't fire more often than every 5 seconds. This amount of time is under review so feel free to suggest the great things you would do with a lower cooldown period via the forums!\u003c/p\u003e","metadata":{"class":"element alert-element build-alert alert-warning","markdown":"Actions have a cooldown and won't fire more often than every 5 seconds. This amount of time is under review so feel free to suggest the great things you would do with a lower cooldown period via the forums!","alert_type":"warning"}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eSo for super simplicity, I've got 3 actions:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eIf on-board button pressed, set\u0026nbsp;\u003ccode\u003ecounter\u003c/code\u003e feed to desired \u003cem\u003eBright White Light time\u003c/em\u003e divided by sensor period\u003cbr\u003ee.g. for 30seconds of white light at 5seconds CO2 period then counter would be set to 6 (or 60 = 5mins).\u003cbr\u003e\u003cbr\u003e\n\u003c/li\u003e\n\u003cli\u003eIf \u003ccode\u003ecounter\u003c/code\u003e feed is greater than one, set NeoPixel strip to Bright White Light (i.e. html colour code #ffffff )\u003cbr\u003e\u003cbr\u003e\n\u003c/li\u003e\n\u003cli\u003eWhenever CO2 data arrives check if \u003ccode\u003ecounter\u003c/code\u003e is less than one, if so then change LED based on CO2 levels, otherwise just decrease \u003ccode\u003ecounter\u003c/code\u003e by 1.\u003c/li\u003e\n\u003c/ol\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch1\u003eAction 1: Button pressed =\u0026gt; reset counter\u003c/h1\u003e\n\u003cp\u003ePicking the Trigger block that checks when a certain value is received is the first (and most challenging step) for this action. Select the Boot button feed from the feeds dropdown inside the trigger block you've placed in the Triggers section of the block diagram.\u003c/p\u003e\n\u003cp\u003eThen we use the Feeds blocks to\u0026nbsp;\u003cstrong\u003eset\u003c/strong\u003e a value for a feed, in this case the\u0026nbsp;\u003ccode\u003ecounter\u003c/code\u003e feed.\u003cbr\u003eWe use the value that represents how many CO2 readings to count down before allowing the light to change back from white to the air indication colour. I've used 5 in this demo.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/771/original/image.png?1746048726","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eHere it might be appropriate to use the Settings cog on the Triggers: section of the block diagram, where an optionally resettable delay can be configured, allowing a form of debouncing (ignore rapidly repeated signals).\u003c/p\u003e\n\u003ch1\u003eAction 2: If counter is active, set LEDs to White\u003c/h1\u003e\n\u003cp\u003eAnother simple action, where we check the value of the counter is at least 1 in the trigger. By doing this instead of triggering on each data point the action will not be affected by the cooldown if the counter reached zero and then was instantly reset. The output feed is obviously the NeoPixel feed (I'm using a Sparkle Motion mini board).\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/772/original/image.png?1746049215","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch1\u003eAction 3: The Big One - Counting down and Colours\u003c/h1\u003e\n\u003cp\u003eIt's not as bad as it sounds, we check if the counter is greater than 0, if so we decrement it by 1 because a countdown is obviously taking place.\u003c/p\u003e\n\u003cp\u003eAlternatively if the counter is 0 then we can use the current air quality to set an appropriate LED colour.\u003c/p\u003e\n\u003cp\u003eThis requires the Maths blocks (change the addition/plus operator to a minus), and some Logic blocks for the If/Else-If/Else sections along with the conditionals (checking if a value meets a condition like \"is less than\"). Note that there are two types of conditional checking blocks, one for numbers and one for strings/text.\u003c/p\u003e\n\u003ch4\u003eGet it set up:\u003c/h4\u003e\n\u003cp\u003eTrigger every time your sensor gets new data, as this should be a stable polling period and will be used as our counter's \u003cem\u003etick\u003c/em\u003e period.\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eThen there is one block of IF/ELSE and the first IF section checks the counter is greater than 1, and decrements it if so, otherwise (ELSE) we use another (nested) IF/ELSE-IF/ELSE block examine the CO2 level is less than 1200 (or 900, or finally is above 1200 in the final Else block).\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eBased on those last 3 checks we publish different colours to the NeoPixel feed.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/773/original/image.png?1746050168","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch1\u003eTesting\u003c/h1\u003e\n\u003cp\u003ePress the button and expect the light to change, otherwise let us know (after you've verified connectivity).\u003c/p\u003e\n\u003cp\u003eIt's worth checking the counter feed too. Also manually add data to the triggering feed if the button is not behaving as expected or you wish to test alternative CO2 values.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/774/original/image.png?1746051003","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n        \u003cp\u003eDid mine work first time? Yes! Did it work reliably afterwards... not so much, well at least not 100% of the time.\u003c/p\u003e\n\u003cp\u003eIt appears my USB cable from the PC is underpowering the device + NeoPixels, an easy fix (more USB power).\u003c/p\u003e\n\u003cp\u003eFor now I'll create a dashboard to reset the counter too. Maybe I should have a button for 5mins and another for 30mins etc, as each button would just set a different counter value. The dashboards work well on the phone once you realise about resizing the dashboard to a small size before editing.\u003c/p\u003e\n      \n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/777/original/image.png?1746117368","metadata":{}},{"element_type":"text","content":"\n        \u003cp\u003eWhen creating the buttons, don't forget to clear out the \u003cstrong\u003eRelease value\u003c/strong\u003e, so it only sends data as the button is depressed rather than also when released.\u003c/p\u003e\n      ","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/778/original/image.png?1746117871","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eThe RUN button on the Edit Action pages will show you the actions output and last few attempts which can help.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/775/original/image.png?1746051308","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eThat's all for now folks!\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}}]