Software Overview  |  Sitemap  |  Downloads  |  Developers  |  Forums
Small_clear_logo_llc

Recipe to Blink an Arduino's LED

Arduinos have a built in LED connected to digital pin 13. On many Arduino sites, there are Arduino example programs which blink this LED. Instead of writing an Arduino program to blink its LED, this Script blinks the Arduino's LED using Virtual Wiring. In this example, we use an Oscillator Device with a user defined period to blink the LED. Any device with an on/off kind of output terminal could be virtuallly wired to the Arduino LED with the same effect.

Ingredients

For this recipe, you will need:

  • an Arduino (running Firmata)

Script

You can find the Script in the Scripts "examples" area. The Script is called "blinking_led.script". The Script is as follows:

# This blinks the built in LED on an Arduino.  The LED is found on Arduino
# pin 13.
# Requires an Arduino.


# Define internal variables
LED_PIN = 13


# Get the file name of the Arduino device.
# On *nix systems, the file will be in the "/dev" directory with
# a name like "/dev/cu.usbmodem411" or "/dev/ttyUSB0".
# On Windows systems, the name will be something like "COM1", "COM2", ....
script_parameters("arduino_port")


# Get the blink period - default to 1Hz
optional_script_parameters(osc_period:1)



# add arduino device
run_script("Scripts/Device/Arduino/Arduino", port_location:arduino_port, id:"arduino")

# make the pin of the LED an output port
run_script("Scripts/Device/Arduino/PinTypes/DigitalOutputs", names:"led", pins:LED_PIN, arduino_id:"arduino")


# create an oscillator
run_script("Scripts/Device/Virtual/Logic/Active/Oscillator" ,id:"oscillator", period:osc_period)



# wire oscillator to the light
wire "oscillator:out","arduino:led"

To run this Script, you need 2 parameters: the arduino_port and osc_period parameters. The arduino_port parameter is the name of the USB port where the Arduino is plugged in. On *nix hosts, the USB port name is in the "/dev" directory. To see the devices in order of their creation, type "ls -lrt /dev" at a shell prompt and look near the bottom of the list for your Arduino's USB port. The osc_period parameter sets the blink period in seconds. It has a default value of 1 second (1Hz).

As an example, for an Arduino at USB port "/dev/ttyUSB0" with a blink frequency of 2Hz, the Script parameters are:

arduino_port: "/dev/ttyUSB0"
osc_period: 0.5

Running the Script

Run the Script above with your own parameters. The LED on your Arduino board should start blinking. Restart the system and try running the system with different blink periods.

Catalina Computing, LLC.

Copyright © Catalina Computing, LLC. (2013-2018)




Page last updated: Thu Apr 3 02:20:48 2014 (UTC)