Skip to content

Instantly share code, notes, and snippets.

@hhayley
Created February 28, 2018 06:22
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 hhayley/f6b3731099c547eed7a3ea538ec3f7d8 to your computer and use it in GitHub Desktop.
Save hhayley/f6b3731099c547eed7a3ea538ec3f7d8 to your computer and use it in GitHub Desktop.
/*
Edited 'sACN intro.ino' for using a push button
It requires 'arduino_secrets.h'file with SSID and password info.
This sketch creates a sACN packet, then uses it to send
fade information to an sACN receiver.
This was originally tested with a DMXKing eDMX1 Pro
and a Coemar LEDko Revlection series spot.
https://dmxking.com/artnetsacn/edmx1-pro
http://www.coemar.com/bin/index.php?id=22&serie=2&lng=en&tipologia=1
Channels used on the LEDko reflection:
1 - brightness
2 - red
3 - green
4 - blue
You'll also need to add a tab to your sketch called arduino_secrets.h
for the SSID and password of the network to which you plan to connect,
as follows:
#define SECRET_SSID "ssid" // fill in your value
#define SECRET_PASS "password" // fill in your value
created 17 Jan 2018
updated 19 Feb 2018
by Tom Igoe
*/
#include <SPI.h>
#include <WiFi101.h>
//#include <ESP8266WiFi.h> // This should work with the ESP8266 as well.
#include <WiFiUdp.h>
#include <sACNSource.h>
#include "arduino_secrets.h"
WiFiUDP Udp; // instance of UDP library
sACNSource myController(Udp); // Your Ethernet-to-DMX device
char receiverAddress[] = "128.122.151.182"; // sACN receiver address
int myUniverse = 1; // DMX universe
char myDevice[] = "myDeviceName"; // sender name
char myUuid[] = "130edd1b-2d17-4289-97d8-2bff1f4490fb"; // sender UUID
int btn = 13;
int led = 14;
int buttonState = 0; // current state of the button
int lastButtonState = 0;
void setup() {
Serial.begin(9600);
// while you're not connected to a WiFi AP,
while ( WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(SECRET_SSID); // print the network name (SSID)
WiFi.begin(SECRET_SSID, SECRET_PASS); // try to connect
delay(2000);
}
// initialize sACN source:
myController.begin(myDevice, myUuid, myUniverse);
// When you're connected, print out the device's network status:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
pinMode(btn, INPUT);
pinMode(led, OUTPUT);
// set DMX channel values to 0:
for (int dmxChannel = 1; dmxChannel < 513; dmxChannel++) {
myController.setChannel(dmxChannel, 0);
}
}
void loop() {
buttonState = digitalRead(btn);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
myController.setChannel(81, 20);
myController.setChannel(61, 20);
digitalWrite(led, HIGH);
} else {
myController.setChannel(81, 0);
myController.setChannel(61, 0);
digitalWrite(led, LOW);
}
myController.sendPacket(receiverAddress);
}
lastButtonState = buttonState;
// // fade up:
// for (int level = 0; level < 256; level++) {
// myController.setChannel(3, level); // set channel 1 (brightness)
// Serial.println(level); // print level
// myController.sendPacket(receiverAddress); // send the data
// delay(100); // wait .1 second
// }
// delay(1000);
//
// // fade down:
// for (int level = 255; level >= 0; level--) {
// myController.setChannel(3, level); // set channel 1 (brightness)
// Serial.println(level); // print level
// myController.sendPacket(receiverAddress); // send the data
// delay(100); // wait .1 second
// }
// delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment