Lesson 7 Traffic Light Simulator - levizzzle/CS490 GitHub Wiki
Lesson 7: Involves installing and setting up Node Red as well as setting up the use of Arduino nodes for input and output. For this project we used the output nodes to write values from pins on the Arduino. First we went through the setup and examples which had us create the package.json, lower-case.html and lower-case.js files. Then we designed a simple flow to convert text to all lower case using the node that we imported by creating the respective files. After that we created a simple Celsius to Fahrenheit conversion flow using an expression function node. The ending task of this lesson was to design a Traffic Light Simulator by utilizing Green/Yellow/Red LEDs and to switch from each color like a traffic light. To do this I used combination of delay and trigger nodes to simulate the stages of a changing traffic light.
Components used:
- Arduino Uno R3
 - Breadboard
 - 5mm Green/Yellow/Red LEDs
 - Node Red
 
Screenshot of Node Red Flow
package.json------------------------------------------------
{
  "name": "node-red-contrib-levi-lower-case",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}lower-case.js------------------------------------------------
module.exports = function(RED) {
    function LowerCaseNode(config) {
        RED.nodes.createNode(this,config);
        var node = this;
        node.on('input', function(msg) {
            msg.payload = msg.payload.toLowerCase();
            node.send(msg);
        });
    }
    RED.nodes.registerType("lower-case",LowerCaseNode);
}lower-case.html------------------------------------------------
<script type="text/javascript">
    RED.nodes.registerType('lower-case',{
        category: 'function',
        color: '#a6bbcf',
        defaults: {
            name: {value:""}
        },
        inputs:1,
        outputs:1,
        icon: "file.png",
        label: function() {
            return this.name||"lower-case";
        }
    });
</script>
<script type="text/html" data-template-name="lower-case">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
</script>
<script type="text/html" data-help-name="lower-case">
    <p>A simple node that converts the message payloads into all lower-case characters</p>
</script>Things Learned
Lesson 7 introduced us to Node Red and much of it involved learning how to install the respective packages in the appropriate directory using command prompt. I learned the basics of running and using Node Red. I also learned how to create our own node and import it into Node Red. Lastly I learned how to implement the Arduino module into Node Red and how to send output to the desired output pins.
