Fertige Ardublock & Code für CO2 Ampel auf Octopus Basis

by

Lange habe ich mich gesträubt einen fertigen Code bzw. ein Bild eines fertigen Ardublock Codes zu veröffentlichen für die CO2, so ist ja ein Teil des Spaßes an den Workshops selbst mithilfe der Fallunterscheidungen (wenn/dann/sonst) herauszufinden, wie man sich so eine Ampel baut. Aber im letzten Bastelworkshop hat ein Teilnehmer den folgenden coolen Code für einen CO2 Ampel auf Octopus Platinen Basis entwickelt:

Was macht der Code: Ganz oben sehen wir die Zahl-Variabel, die bezeichnet die Werte aus dem CO2 Sensor. Als erstes wird der Wert im LCD Display angezeigt. So weit unspektakulär. Dann aber wird es spannend.

Pi & Octopus 🐙

Die erste Falls/Sonst Unterscheidung testet ob der CO2 Sensor überhaupt einen sinnvollen Wert liefert. Wenn er aber 0 ausgibt, dann blinkt der rechte Neopixel blau/weiß. Die nächsten beiden Fall/Sonst Unterscheidungen arbeiten dann wie immer bei den Ampeln: Zunächst wird geprüft ob der Wert größer ist als 1000 ppm CO2. Wenn ja dann blinkt der rechte Neopixel rot. Wenn nein dann bei über 700 leuchtet sie gelb und bei unter 700 leuchtet sie grün.

fertiger Code

Dies ist der Code um es wieder in die Ardublock Oberfläche hineinzukopieren. Daher einfach das kopieren, in einen Text Editor einfügen und mit der Endung .abp Abspeichern.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<cb:CODEBLOCKS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://education.mit.edu/openblocks/ns http://education.mit.edu/openblocks/codeblocks.xsd" xmlns:cb="http://education.mit.edu/openblocks/ns">
<Pages collapsible-pages="yes" drawer-with-page="yes">
<Page page-color="128 128 128" page-drawer="Main" page-infullview="yes" page-name="Main" page-width="1920">
<PageBlocks>
<Block genus-name="message" id="510">
<Label>message</Label>
<Location>
<X>866</X>
<Y>1579</Y>
</Location>
<Plug>
<BlockConnector connector-kind="plug" connector-type="string" init-type="string" label="" position-type="single"/>
</Plug>
<Sockets num-sockets="1">
<BlockConnector connector-kind="socket" connector-type="string" init-type="string" label="" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="setter_variable_number" id="231">
<Location>
<X>188</X>
<Y>116</Y>
</Location>
<BeforeBlockId>167</BeforeBlockId>
<AfterBlockId>196</AfterBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="232" connector-kind="socket" connector-type="number" init-type="number" label="Variable" position-type="single"/>
<BlockConnector con-block-id="200" connector-kind="socket" connector-type="number" init-type="number" label="Wert" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="LCDGroveRGB" id="196">
<Location>
<X>188</X>
<Y>205</Y>
</Location>
<BeforeBlockId>231</BeforeBlockId>
<AfterBlockId>187</AfterBlockId>
<Sockets num-sockets="3">
<BlockConnector con-block-id="197" connector-kind="socket" connector-type="number" init-type="number" label="x" position-type="single"/>
<BlockConnector con-block-id="198" connector-kind="socket" connector-type="number" init-type="number" label="y" position-type="single"/>
<BlockConnector con-block-id="199" connector-kind="socket" connector-type="string" init-type="string" label="text" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="ifelse" id="187">
<Location>
<X>188</X>
<Y>283</Y>
</Location>
<BeforeBlockId>196</BeforeBlockId>
<Sockets num-sockets="3">
<BlockConnector con-block-id="256" connector-kind="socket" connector-type="boolean" init-type="boolean" label="teste" position-type="single"/>
<BlockConnector con-block-id="268" connector-kind="socket" connector-type="cmd" init-type="cmd" label="dann" position-type="single"/>
<BlockConnector con-block-id="224" connector-kind="socket" connector-type="cmd" init-type="cmd" label="sonst" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="ifelse" id="224">
<Location>
<X>322</X>
<Y>498</Y>
</Location>
<BeforeBlockId>187</BeforeBlockId>
<Sockets num-sockets="3">
<BlockConnector con-block-id="247" connector-kind="socket" connector-type="boolean" init-type="boolean" label="teste" position-type="single"/>
<BlockConnector con-block-id="273" connector-kind="socket" connector-type="cmd" init-type="cmd" label="dann" position-type="single"/>
<BlockConnector con-block-id="246" connector-kind="socket" connector-type="cmd" init-type="cmd" label="sonst" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="ifelse" id="246">
<Label>Falls/sonst</Label>
<Location>
<X>456</X>
<Y>881</Y>
</Location>
<BeforeBlockId>224</BeforeBlockId>
<Sockets num-sockets="3">
<BlockConnector con-block-id="237" connector-kind="socket" connector-type="boolean" init-type="boolean" label="teste" position-type="single"/>
<BlockConnector con-block-id="250" connector-kind="socket" connector-type="cmd" init-type="cmd" label="dann" position-type="single"/>
<BlockConnector con-block-id="259" connector-kind="socket" connector-type="cmd" init-type="cmd" label="sonst" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="ifelse" id="259">
<Label>Falls/sonst</Label>
<Location>
<X>590</X>
<Y>982</Y>
</Location>
<BeforeBlockId>246</BeforeBlockId>
<Sockets num-sockets="3">
<BlockConnector con-block-id="222" connector-kind="socket" connector-type="boolean" init-type="boolean" label="teste" position-type="single"/>
<BlockConnector con-block-id="240" connector-kind="socket" connector-type="cmd" init-type="cmd" label="dann" position-type="single"/>
<BlockConnector connector-kind="socket" connector-type="cmd" init-type="cmd" label="sonst" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="iot_neopixel_light" id="240">
<Label>Neopixel</Label>
<Location>
<X>725</X>
<Y>1018</Y>
</Location>
<BeforeBlockId>259</BeforeBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="241" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="242" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="NEOVectorGreen" id="242">
<Location>
<X>855</X>
<Y>1045</Y>
</Location>
<Plug>
<BlockConnector con-block-id="240" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-rechts" id="241">
<Label>Rechts</Label>
<Location>
<X>855</X>
<Y>1021</Y>
</Location>
<Plug>
<BlockConnector con-block-id="240" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="less" id="222">
<Location>
<X>728</X>
<Y>985</Y>
</Location>
<Plug>
<BlockConnector con-block-id="259" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="mirror"/>
</Plug>
<Sockets num-sockets="2">
<BlockConnector con-block-id="236" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
<BlockConnector con-block-id="226" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
</Sockets>
</Block>
<Block genus-name="number" id="226">
<Label>700</Label>
<Location>
<X>831</X>
<Y>988</Y>
</Location>
<Plug>
<BlockConnector con-block-id="222" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="variable_number" id="236">
<Label>co2</Label>
<Location>
<X>738</X>
<Y>988</Y>
</Location>
<Plug>
<BlockConnector con-block-id="222" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="iot_neopixel_light" id="250">
<Label>Neopixel</Label>
<Location>
<X>591</X>
<Y>917</Y>
</Location>
<BeforeBlockId>246</BeforeBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="251" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="252" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="NEOVectorYellow" id="252">
<Location>
<X>721</X>
<Y>944</Y>
</Location>
<Plug>
<BlockConnector con-block-id="250" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-rechts" id="251">
<Label>Rechts</Label>
<Location>
<X>721</X>
<Y>920</Y>
</Location>
<Plug>
<BlockConnector con-block-id="250" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="greater_equal" id="237">
<Location>
<X>594</X>
<Y>884</Y>
</Location>
<Plug>
<BlockConnector con-block-id="246" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="mirror"/>
</Plug>
<Sockets num-sockets="2">
<BlockConnector con-block-id="238" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
<BlockConnector con-block-id="239" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
</Sockets>
</Block>
<Block genus-name="number" id="239">
<Label>700</Label>
<Location>
<X>704</X>
<Y>887</Y>
</Location>
<Plug>
<BlockConnector con-block-id="237" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="variable_number" id="238">
<Label>co2</Label>
<Location>
<X>604</X>
<Y>887</Y>
</Location>
<Plug>
<BlockConnector con-block-id="237" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="iot_neopixel_light" id="273">
<Label>Neopixel</Label>
<Location>
<X>457</X>
<Y>534</Y>
</Location>
<BeforeBlockId>224</BeforeBlockId>
<AfterBlockId>276</AfterBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="274" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="275" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="delay" id="276">
<Label>Warte</Label>
<Location>
<X>457</X>
<Y>588</Y>
</Location>
<BeforeBlockId>273</BeforeBlockId>
<AfterBlockId>278</AfterBlockId>
<Sockets num-sockets="1">
<BlockConnector con-block-id="277" connector-kind="socket" connector-type="number" init-type="number" label="Millisekunden" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="iot_neopixel_light" id="278">
<Label>Neopixel</Label>
<Location>
<X>457</X>
<Y>618</Y>
</Location>
<BeforeBlockId>276</BeforeBlockId>
<AfterBlockId>281</AfterBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="279" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="280" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="delay" id="281">
<Label>Warte</Label>
<Location>
<X>457</X>
<Y>672</Y>
</Location>
<BeforeBlockId>278</BeforeBlockId>
<AfterBlockId>283</AfterBlockId>
<Sockets num-sockets="1">
<BlockConnector con-block-id="282" connector-kind="socket" connector-type="number" init-type="number" label="Millisekunden" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="iot_neopixel_light" id="283">
<Label>Neopixel</Label>
<Location>
<X>457</X>
<Y>702</Y>
</Location>
<BeforeBlockId>281</BeforeBlockId>
<AfterBlockId>286</AfterBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="284" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="285" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="delay" id="286">
<Label>Warte</Label>
<Location>
<X>457</X>
<Y>756</Y>
</Location>
<BeforeBlockId>283</BeforeBlockId>
<AfterBlockId>288</AfterBlockId>
<Sockets num-sockets="1">
<BlockConnector con-block-id="287" connector-kind="socket" connector-type="number" init-type="number" label="Millisekunden" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="iot_neopixel_light" id="288">
<Label>Neopixel</Label>
<Location>
<X>457</X>
<Y>786</Y>
</Location>
<BeforeBlockId>286</BeforeBlockId>
<AfterBlockId>291</AfterBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="289" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="290" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="delay" id="291">
<Label>Warte</Label>
<Location>
<X>457</X>
<Y>840</Y>
</Location>
<BeforeBlockId>288</BeforeBlockId>
<Sockets num-sockets="1">
<BlockConnector con-block-id="292" connector-kind="socket" connector-type="number" init-type="number" label="Millisekunden" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="number" id="292">
<Label>300</Label>
<Location>
<X>601</X>
<Y>843</Y>
</Location>
<Plug>
<BlockConnector con-block-id="291" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="NEOVectorOff" id="290">
<Label>Aus</Label>
<Location>
<X>587</X>
<Y>813</Y>
</Location>
<Plug>
<BlockConnector con-block-id="288" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-links" id="289">
<Location>
<X>587</X>
<Y>789</Y>
</Location>
<Plug>
<BlockConnector con-block-id="288" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="number" id="287">
<Label>300</Label>
<Location>
<X>601</X>
<Y>759</Y>
</Location>
<Plug>
<BlockConnector con-block-id="286" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="NEOVectorRed" id="285">
<Label>Rot</Label>
<Location>
<X>587</X>
<Y>729</Y>
</Location>
<Plug>
<BlockConnector con-block-id="283" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-links" id="284">
<Location>
<X>587</X>
<Y>705</Y>
</Location>
<Plug>
<BlockConnector con-block-id="283" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="number" id="282">
<Label>300</Label>
<Location>
<X>601</X>
<Y>675</Y>
</Location>
<Plug>
<BlockConnector con-block-id="281" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="NEOVectorOff" id="280">
<Location>
<X>587</X>
<Y>645</Y>
</Location>
<Plug>
<BlockConnector con-block-id="278" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-rechts" id="279">
<Label>Rechts</Label>
<Location>
<X>587</X>
<Y>621</Y>
</Location>
<Plug>
<BlockConnector con-block-id="278" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="number" id="277">
<Label>300</Label>
<Location>
<X>601</X>
<Y>591</Y>
</Location>
<Plug>
<BlockConnector con-block-id="276" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="NEOVectorRed" id="275">
<Location>
<X>587</X>
<Y>561</Y>
</Location>
<Plug>
<BlockConnector con-block-id="273" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-rechts" id="274">
<Label>Rechts</Label>
<Location>
<X>587</X>
<Y>537</Y>
</Location>
<Plug>
<BlockConnector con-block-id="273" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="greater" id="247">
<Label>></Label>
<Location>
<X>460</X>
<Y>501</Y>
</Location>
<Plug>
<BlockConnector con-block-id="224" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="mirror"/>
</Plug>
<Sockets num-sockets="2">
<BlockConnector con-block-id="248" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
<BlockConnector con-block-id="249" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
</Sockets>
</Block>
<Block genus-name="number" id="249">
<Label>1000</Label>
<Location>
<X>563</X>
<Y>504</Y>
</Location>
<Plug>
<BlockConnector con-block-id="247" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="variable_number" id="248">
<Label>co2</Label>
<Location>
<X>470</X>
<Y>504</Y>
</Location>
<Plug>
<BlockConnector con-block-id="247" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="iot_neopixel_light" id="268">
<Label>Neopixel</Label>
<Location>
<X>323</X>
<Y>319</Y>
</Location>
<BeforeBlockId>187</BeforeBlockId>
<AfterBlockId>271</AfterBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="269" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="270" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="delay" id="271">
<Label>Warte</Label>
<Location>
<X>323</X>
<Y>373</Y>
</Location>
<BeforeBlockId>268</BeforeBlockId>
<AfterBlockId>253</AfterBlockId>
<Sockets num-sockets="1">
<BlockConnector con-block-id="272" connector-kind="socket" connector-type="number" init-type="number" label="Millisekunden" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="iot_neopixel_light" id="253">
<Label>Neopixel</Label>
<Location>
<X>323</X>
<Y>403</Y>
</Location>
<BeforeBlockId>271</BeforeBlockId>
<AfterBlockId>266</AfterBlockId>
<Sockets num-sockets="2">
<BlockConnector con-block-id="254" connector-kind="socket" connector-type="number" init-type="number" label="Ort" position-type="single"/>
<BlockConnector con-block-id="255" connector-kind="socket" connector-type="boolean" init-type="boolean" label="Farbe" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="delay" id="266">
<Location>
<X>323</X>
<Y>457</Y>
</Location>
<BeforeBlockId>253</BeforeBlockId>
<Sockets num-sockets="1">
<BlockConnector con-block-id="267" connector-kind="socket" connector-type="number" init-type="number" label="Millisekunden" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="number" id="267">
<Label>1000</Label>
<Location>
<X>467</X>
<Y>460</Y>
</Location>
<Plug>
<BlockConnector con-block-id="266" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="NEOVectorWhite" id="255">
<Location>
<X>453</X>
<Y>430</Y>
</Location>
<Plug>
<BlockConnector con-block-id="253" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-rechts" id="254">
<Label>Rechts</Label>
<Location>
<X>453</X>
<Y>406</Y>
</Location>
<Plug>
<BlockConnector con-block-id="253" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="number" id="272">
<Label>1000</Label>
<Location>
<X>467</X>
<Y>376</Y>
</Location>
<Plug>
<BlockConnector con-block-id="271" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="NEOVectorBlue" id="270">
<Label>Blau</Label>
<Location>
<X>453</X>
<Y>346</Y>
</Location>
<Plug>
<BlockConnector con-block-id="268" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="neo-rechts" id="269">
<Label>Rechts</Label>
<Location>
<X>453</X>
<Y>322</Y>
</Location>
<Plug>
<BlockConnector con-block-id="268" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="equal" id="256">
<Location>
<X>326</X>
<Y>286</Y>
</Location>
<Plug>
<BlockConnector con-block-id="187" connector-kind="plug" connector-type="boolean" init-type="boolean" label="" position-type="mirror"/>
</Plug>
<Sockets num-sockets="2">
<BlockConnector con-block-id="257" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
<BlockConnector con-block-id="258" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="bottom"/>
</Sockets>
</Block>
<Block genus-name="number" id="258">
<Label>0</Label>
<Location>
<X>436</X>
<Y>289</Y>
</Location>
<Plug>
<BlockConnector con-block-id="256" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="variable_number" id="257">
<Label>co2</Label>
<Location>
<X>336</X>
<Y>289</Y>
</Location>
<Plug>
<BlockConnector con-block-id="256" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="message" id="199">
<Label>co2:_</Label>
<Location>
<X>370</X>
<Y>256</Y>
</Location>
<Plug>
<BlockConnector con-block-id="196" connector-kind="plug" connector-type="string" init-type="string" label="" position-type="single"/>
</Plug>
<Sockets num-sockets="1">
<BlockConnector con-block-id="202" connector-kind="socket" connector-type="string" init-type="string" label="" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="glue_sn" id="202">
<Location>
<X>434</X>
<Y>256</Y>
</Location>
<Plug>
<BlockConnector con-block-id="199" connector-kind="plug" connector-type="string" init-type="string" label="" position-type="single"/>
</Plug>
<Sockets num-sockets="1">
<BlockConnector con-block-id="234" connector-kind="socket" connector-type="number" init-type="number" label="" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="variable_number" id="234">
<Label>co2</Label>
<Location>
<X>518</X>
<Y>256</Y>
</Location>
<Plug>
<BlockConnector con-block-id="202" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="number" id="198">
<Label>0</Label>
<Location>
<X>370</X>
<Y>232</Y>
</Location>
<Plug>
<BlockConnector con-block-id="196" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="number" id="197">
<Label>0</Label>
<Location>
<X>370</X>
<Y>208</Y>
</Location>
<Plug>
<BlockConnector con-block-id="196" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="GetSCD30" id="200">
<Location>
<X>400</X>
<Y>143</Y>
</Location>
<Plug>
<BlockConnector con-block-id="231" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
<Sockets num-sockets="1">
<BlockConnector con-block-id="201" connector-kind="socket" connector-type="number" init-type="number" label="Sensor" position-type="single"/>
</Sockets>
</Block>
<Block genus-name="SCD30VectorCO2" id="201">
<Label>CO2</Label>
<Location>
<X>626</X>
<Y>143</Y>
</Location>
<Plug>
<BlockConnector con-block-id="200" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="single"/>
</Plug>
</Block>
<Block genus-name="variable_number" id="232">
<Label>co2</Label>
<Location>
<X>400</X>
<Y>119</Y>
</Location>
<Plug>
<BlockConnector con-block-id="231" connector-kind="plug" connector-type="number" init-type="number" label="" position-type="mirror"/>
</Plug>
</Block>
<Block genus-name="program" id="167">
<Location>
<X>40</X>
<Y>73</Y>
</Location>
<Sockets num-sockets="2">
<BlockConnector connector-kind="socket" connector-type="cmd" init-type="cmd" label="Setup" position-type="single"/>
<BlockConnector con-block-id="231" connector-kind="socket" connector-type="cmd" init-type="cmd" label="Schleife" position-type="single"/>
</Sockets>
</Block>
</PageBlocks>
</Page>
</Pages>
</cb:CODEBLOCKS>

Den fertigen Code aus dem Arduino IDE findet ihr hier. Diesen könnt ihr einfach per Copy+Paste in die Arduino IDE einfügen:

/* This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details. */
#include <SparkFun_SCD30_Arduino_Library.h>
#include <Wire.h>
#include <rgb_lcd.h>
#include <Adafruit_NeoPixel.h>
#include <ESP8266WiFi.h>
int co2 = 0 ;
//Reading CO2, humidity and temperature from the SCD30 By: Nathan Seidle SparkFun Electronics 
//https://github.com/sparkfun/SparkFun_SCD30_Arduino_Library
SCD30 airSensorSCD30; // Objekt SDC30 Umweltsensor
//LCD RGB, 2013 Copyright (c) Seeed Technology Inc.   Author:Loovee
rgb_lcd lcd;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(2,13,NEO_GRBW + NEO_KHZ800);
void setup(){ // Einmalige Initialisierung
  WiFi.forceSleepBegin(); // Wifi off
  Wire.begin(); // ---- Initialisiere den I2C-Bus 
  if (Wire.status() != I2C_OK) Serial.println("Something wrong with I2C");
  if (airSensorSCD30.begin() == false) {
    Serial.println("The SCD30 did not respond. Please check wiring."); 
    while(1) {
      yield(); 
      delay(1);
    } 
  }
  airSensorSCD30.setAutoSelfCalibration(false); // Sensirion no auto calibration
  airSensorSCD30.setMeasurementInterval(2);     // CO2-Messung alle 5 s
  Serial.begin(115200);
  lcd.begin(16, 2);// LCD Backlight initialisieren 
  pixels.begin();//-------------- Initialisierung Neopixel
  delay(1);
  pixels.show();
  pixels.setPixelColor(0,0,0,0,0); // alle aus
  pixels.setPixelColor(1,0,0,0,0);
  pixels.show();                 // und anzeigen
  Wire.setClock(100000L);            // 100 kHz SCD30 
  Wire.setClockStretchLimit(200000L);// CO2-SCD30
}
void loop() { // Kontinuierliche Wiederholung 
  co2 = airSensorSCD30.getCO2() ;
  lcd.setCursor(0,0);
  lcd.print(String("co2:_"+String(String(co2)))+"                ");
  if (( ( co2 ) == ( 0 ) ))
  {
    pixels.setPixelColor(0,0,0,30,0);
    pixels.show();	
    delay( 1000 );
    pixels.setPixelColor(0,0,0,0,30);
    pixels.show();	
    delay( 1000 );
  }
  else
  {
    if (( ( co2 ) > ( 1000 ) ))
    {
      pixels.setPixelColor(0,40,0,0,0);
      pixels.show();	
      delay( 300 );
      pixels.setPixelColor(0,0,0,0,0);
      pixels.show();	
      delay( 300 );
      pixels.setPixelColor(1,40,0,0,0);
      pixels.show();	
      delay( 300 );
      pixels.setPixelColor(1,0,0,0,0);
      pixels.show();	
      delay( 300 );
    }
    else
    {
      if (( ( co2 ) >= ( 700 ) ))
      {
        pixels.setPixelColor(0,30,30,0,0);
        pixels.show();
      }
      else
      {
        if (( ( co2 ) < ( 700 ) ))
        {
          pixels.setPixelColor(0,0,30,0,0);
          pixels.show();
        }
        else
        {
        }
      }
    }
  }
}

Schlagwörter: , , , , ,

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google Foto

Du kommentierst mit Deinem Google-Konto. Abmelden /  Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


%d Bloggern gefällt das: