Skip to content

Instantly share code, notes, and snippets.

@Electronza
Created December 16, 2019 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Electronza/84965460f79e682874e19f10c9f04f4e to your computer and use it in GitHub Desktop.
Save Electronza/84965460f79e682874e19f10c9f04f4e to your computer and use it in GitHub Desktop.
Arduino DMX slave
/*******************************************************************
____ __ ____ ___ ____ ____ __ __ _ ____ __
( __)( ) ( __)/ __)(_ _)( _ \ / \ ( ( \(__ ) / _\
) _) / (_/\ ) _)( (__ )( ) /( O )/ / / _/ / \
(____)\____/(____)\___) (__) (__\_) \__/ \_)__)(____)\_/\_/
Project name: Arduino DMX slave
Project page: https://electronza.com/arduino-dmx-master-and-slave/
********************************************************************/
/*
Example code for using the Conceptinetics DMX library with RS485 click board from Mikroelectronika
Slave device using 4x4 RGB click and Arduino Uno
CH1: Red
CH2: Blue
CH3: Green
Ver.1.0, 2 November 2015
http://microcontroller-projects.com
Based on:
Conceptinetics DMX library,
Copyright (c) 2013 W.A. van der Meeren <danny@illogic.nl>. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
http://sourceforge.net/projects/dmxlibraryforar/files/
Also inspired by:
NeoPixel Ring simple sketch (c) 2013 Shae Erisson
released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
https://github.com/adafruit/Adafruit_NeoPixel
*/
#include <Conceptinetics.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define SLAVE_CHANNELS 3
#define RXEN_PIN 6
DMX_Slave dmx_slave ( SLAVE_CHANNELS , RXEN_PIN );
// Which pin on the Arduino is connected to the NeoPixels?
// If the 4x4 RGB click is in socket #2 the pin is A2
#define LED_PIN A2
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 16
// the LEDs should not be drivel at full intensity
// or they will overheat
#define MAXLEVEL 150
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
// See the explanations from the Adafruit library
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Enable DMX slave interface and start recording
dmx_slave.onReceiveComplete (OnFrameReceiveComplete);
dmx_slave.enable ();
// Set start address to 1, this is also the default setting
// You can change this address at any time during the program
dmx_slave.setStartAddress (1);
pixels.begin(); // This initializes the NeoPixel library.
// now we turn off the neopixels
for(int i=0; i< NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Off.
pixels.show(); // This sends the updated pixel color to the hardware.
}
}
void loop() {
// put your main code here, to run repeatedly:
}
void OnFrameReceiveComplete (unsigned short ch)
{
// Called every time when it collected its data
// and no interference from other interrupts
int red;
int blue;
int green;
// map(value, fromLow, fromHigh, toLow, toHigh)
red = map ( dmx_slave.getChannelValue(1) ,0 , 255, 0, MAXLEVEL);
blue = map ( dmx_slave.getChannelValue(2) ,0 , 255, 0, MAXLEVEL);
green = map ( dmx_slave.getChannelValue(3) ,0 , 255, 0, MAXLEVEL);
// now we send data to the neopixels
for(int i=0; i< 16;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(red,green,blue)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment