Skip to content

Instantly share code, notes, and snippets.

@5shekel
Created November 24, 2015 17:00
Show Gist options
  • Save 5shekel/24dc15c8130c682ad6e0 to your computer and use it in GitHub Desktop.
Save 5shekel/24dc15c8130c682ad6e0 to your computer and use it in GitHub Desktop.
// - - - - -
// DmxSerial - A hardware supported interface to DMX.
// DmxSerialSend.ino: Sample DMX application for sending 3 DMX values:
//
// 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
//
// 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
// - - - - -
#include <DMXSerial.h>
// The color fading pattern
int RedList[] = {255, 128, 0, 0, 0, 128};
int GreenList[] = { 0, 128, 255, 128, 0, 0};
int BlueList[] = { 0, 0, 0, 128, 255, 128};
int RedLevel, GreenLevel, BlueLevel;
int RedNow = 0;
int GreenNow = 0;
int BlueNow = 0;
int state = 0;
void setup() {
DMXSerial.init(DMXController);
} // setup
// loop through the rainbow colors
void loop() {
RedLevel = RedList[state];
GreenLevel = GreenList[state];
BlueLevel = BlueList[state];
if ((RedLevel == RedNow) && (GreenLevel == GreenNow) && (BlueLevel == BlueNow)) {
state += 1;
if (state == 6)
state = 0;
} else {
if (RedNow < RedLevel) RedNow++;
if (RedNow > RedLevel) RedNow--;
DMXSerial.write(1, RedNow);
if (GreenNow < GreenLevel) GreenNow++;
if (GreenNow > GreenLevel) GreenNow--;
DMXSerial.write(2, GreenNow);
if (BlueNow < BlueLevel) BlueNow++;
if (BlueNow > BlueLevel) BlueNow--;
DMXSerial.write(3, BlueNow);
} // if
delayMicroseconds(2000); // wait a little bit
} // loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment