Lab 4: Programming with Streams

Multicolor lamp

Let's replace the simple blinking lamp with a multicolor one.

The purpose of this project is to light up an RGB LED in different colors. In order to achieve this, you need three PWM pins to control the LED and have a say on each of its colors. To work with them, you can add three sliders in the Dashboard and, according on the value they send, to set the intensity of each color.

What you need

  • One Edison connected to Wyliodrin;
  • One RGB LED;
  • Three 200 Ohm resistors;
  • Male-male jumper wires.

The Setup

Connect the RGB LED to the Edison following the schematics in the figure. The RGB LED is simply an LED consisting of three simple LEDs: a red one, a green one and a blue one. Each of these LEDs is controlled by a PWM pin, so that it can light brighter or dimmer. As a result, the color of the RGB LED will be the result of these three colors.

The Code

You go to the Wyliodrin Applications page and create a new application. you name it and select Streams as programming language. The most important thing to do is to choose the node that receives the value given by your sliders. This node connects your application to the dashboard by making it subscribe to signals to be received. Basically, each time a signal is received, the code inside this node gets executed. You can see that the receive signal node also has two parameters: name and signal. Name is of no difficulty, it represents the name of the node and signal the name of the signal the application subscribes to. As you can imply from the node's looks, there is no place in this node where you get a value. Why is that? Because the value in the message received changes its value each time a new signal comes. The dashboard has to send the application a value and this is how they interact: through messages. You can think of this message as of a container. The dashboard places the value inside, then it notifies the application, which gets the value from the container and can simply use it.

Once you have the value from the slider, you write it on the PWM pin, using the analog write function. Now consider the sliders. In their settings you have to name them and make sure their scale is from 0 to 255, as those are the values a PWM pin expects. Once you click the Run the application button, the project will get deployed on the board.

Exercises

  1. Make a Streams application and use it to create a project that will light up a LED for 3 seconds at one press of a button.
  2. Do the same, using a switch from the dashboard instead of the button.
  3. Connect a button that you will have to press in order to turn on an LED and press again to turn the LED off.
  4. The same, only that if you have pressed the button once, for the next two seconds, pressing again the button will have no effect. In a nutshell, once you press the button, it will become inactive for the next two seconds.
  5. The same, but using the switch from the dashboard instead of the button.
  6. Make a chat in Python with your neighbour's board. You read the messages from the keyboard in Python and the messages received will be shown in Python as well. Every time a new message comes, you turn on an LED for a few seconds. This part of the project should be made using streams nodes.
iot2015/labs/04.txt ยท Last modified: 2016/06/17 15:45 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0