In this example we’ll see how to make an LED blink, and control the speed of the blink with a potentiometer. I already have a bread board with an LED hooked up to digital pin 3 from the LED Fade example. I have a 10K potentiometer. Potentiometers come in all shapes and sizes, but I’m using this little one that has pins that plug right into the breadboard. I plug it in so that each pin touches a different terminal strip, make sure not to plug it in with all pins on the same strip. Use jumpers to connect the pin on one side to the voltage channel, and the pin on the other side to the ground channel. It doesn’t matter which is which. Then connect the middle pin to one of the analog in pins, which are marked with an A and a number, I’m using pin A2.
In Embrio I’m going to start with the “blink built in LED” project. I save a copy by selecting Save Project As from the file menu and naming the project copy “Blink LED Speed Control”. The existing project is using the LED built into the Arduino, but I want to use the one I have plugged in, so I change the pin type to Analog and select pin 3 and refresh the connection program. This project already has most of the work done, and the switch that controls the LED is already turning on and off. Notice that the Timer node has a duration input. If I click and drag the value the timer speeds up and the blink goes faster. I want the potentiometer to drive this value, so I add an Input node from Input Output menu and select pin 2, then refresh the connection program. Now when I turn the potentiometer I can see the output on my new node change. I simply connect that output to the timer’s duration input and now the potentiometer controls the speed of the blink.
I’m going to do a couple more things to this project. First I want to make the slowest blink take longer, so I change the timer’s max seconds value from 1 to 2. I also want to limit how fast the LED can blink. If I turn the knob all the way to one side its value is 0. A timer with a duration of 0 fires on every update, but I want to limit it. I disconnect the input node from the timer by either right clicking on the connection line and selecting “delete”, or by holding down the Alt key on my keyboard and clicking on the line. Between these two nodes I add a Transform Number node from the Math menu. I connect the input node to the input activation, and the output activation to the timer. With the potentiometer turned down to 0, I can adjust the Output Min value on the transform number node to set the minimum value. I experiment and set it to something I like, and now my project is done.