Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // - - - - -
- // DmxSerial - A hardware supported interface to DMX.
- // DmxSerialRecv.pde: Sample DMX application for retrieving 3 DMX values:
- // address 1 (yellow) -> PWM Port 9
- // address 2 (green) -> PWM Port 6
- // address 3 (blue) -> PWM Port 5
- // address 4 (red) -> PWM Port 4
- //
- // Copyright (c) 2011 by Matthias Hertel, http://www.mathertel.de
- // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
- // Modified for use with Artemis Spaceship Bridge Simulator
- //
- // Documentation and samples are available at http://www.mathertel.de/Arduino
- // 25.07.2011 creation of the DmxSerial library.
- // 10.09.2011 fully control the serial hardware register
- // without using the Arduino Serial (HardwareSerial) class to avoid ISR implementation conflicts.
- // 01.12.2011 include file and extension changed to work with the Arduino 1.0 environment
- // 28.12.2011 changed to channels 1..3 (RGB) for compatibility with the DmxSerialSend sample.
- // 10.05.2012 added some lines to loop to show how to fall back to a default color when no data was received since some time.
- // - - - - -
- #include <DMXSerial.h>
- // Constants for demo program
- const int YellowPin = 9; // PWM output pin for Yellow Light.
- const int GreenPin = 6; // PWM output pin for Green Light.
- const int BluePin = 5; // PWM output pin for Blue Light.
- const int RedPin = 10; // PWM output pin for Red Light.
- #define YellowDefaultLevel 0
- #define GreenDefaultLevel 0
- #define BlueDefaultLevel 0
- #define RedDefaultLevel 0
- void setup () {
- DMXSerial.init(DMXReceiver);
- // set some default values
- DMXSerial.write(1, 80);
- DMXSerial.write(2, 0);
- DMXSerial.write(3, 0);
- DMXSerial.write(4, 0);
- // enable pwm outputs
- pinMode(YellowPin, OUTPUT); // sets the digital pin as output
- pinMode(GreenPin, OUTPUT);
- pinMode(BluePin, OUTPUT);
- pinMode(RedPin, OUTPUT);
- }
- void loop() {
- // Calculate how long no data backet was received
- unsigned long lastPacket = DMXSerial.noDataSince();
- if (lastPacket < 5000) {
- // read recent DMX values and set pwm levels
- analogWrite(YellowPin, DMXSerial.read(1));
- analogWrite(GreenPin, DMXSerial.read(2));
- analogWrite(BluePin, DMXSerial.read(3));
- analogWrite(RedPin, DMXSerial.read(4));
- } else {
- // Show pure red color, when no data was received since 5 seconds or more.
- analogWrite(YellowPin, RedDefaultLevel);
- analogWrite(GreenPin, GreenDefaultLevel);
- analogWrite(BluePin, BlueDefaultLevel);
- analogWrite(RedPin, RedDefaultLevel);
- } // if
- }
- // End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement