Skip to content

Instantly share code, notes, and snippets.

@pixelistik
Last active August 29, 2015 12:27
Show Gist options
  • Save pixelistik/f39115c1f1d5aa0d21c2 to your computer and use it in GitHub Desktop.
Save pixelistik/f39115c1f1d5aa0d21c2 to your computer and use it in GitHub Desktop.
/*
DMX_Master.ino - Example code for using the Conceptinetics DMX library
Copyright (c) 2013 W.A. van der Meeren <[email protected]>. 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.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Conceptinetics.h>
//
// CTC-DRA-13-1 ISOLATED DMX-RDM SHIELD JUMPER INSTRUCTIONS
//
// If you are using the above mentioned shield you should
// place the RXEN jumper towards pin number 2, this allows the
// master controller to put to iso shield into transmit
// (DMX Master) mode
//
//
// The !EN Jumper should be either placed in the G (GROUND)
// position to enable the shield circuitry
// OR
// if one of the pins is selected the selected pin should be
// set to OUTPUT mode and set to LOGIC LOW in order for the
// shield to work
//
//
// The master will control 100 Channels (1-100)
//
// depending on the ammount of memory you have free you can choose
// to enlarge or schrink the ammount of channels (minimum is 1)
//
#define DMX_MASTER_CHANNELS 100
//
// Pin number to change read or write mode on the shield
//
#define RXEN_PIN 2
// Configure a DMX master controller, the master controller
// will use the RXEN_PIN to control its write operation
// on the bus
DMX_Master dmx_master ( DMX_MASTER_CHANNELS, RXEN_PIN );
int sensorPin = A0;
int sensorValue = 0;
int outputValue = 0;
int knownSensorMax = 0; // Init with lowest possible analog sensor max
int knownSensorMin = 1023; // Init with highest possible analog sensor min
// the setup routine runs once when you press reset:
void setup() {
// Enable DMX master interface and start transmitting
dmx_master.enable ();
// Set channel 1 - 50 @ 50%
dmx_master.setChannelRange ( 2, 25, 127 );
//Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop()
{
sensorValue = analogRead(sensorPin); // 30 - 5
// Update max if higher than known value
if (sensorValue > knownSensorMax) {
knownSensorMax = sensorValue;
}
// Update max if lower than known value
if (sensorValue < knownSensorMin) {
knownSensorMin = sensorValue;
}
// Dark = high resistance = high sensor value
// Map high sensor value to low DMX value
outputValue = map(sensorValue, knownSensorMin, knownSensorMax, 255, 0);
outputValue = constrain(outputValue, 0, 255);
dmx_master.setChannelValue ( 1, outputValue );
delay ( 10 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment