https://tigoe.github.io/LightProjects/fading
Source_Four_LED_Series_2_Datasheet_revP.pdf
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
const int universeSize = 45;
int pressure;
int threshold = 500;
void setup(){
Serial.begin(9600);
// initialize the DMX library with the universe size
if (!DMX.begin(universeSize)) {
Serial.println("Failed to initialize DMX!");
while (true); // wait for ever
}}
void loop() {
pressure = analogRead(A0);
Serial.println(pressure);
if (pressure>threshold){
DMX.beginTransmission();
//we can change the two lights with different effects
//1 Hue (coarse)
//2 – Hue (fine)
//3 – Saturation
// 4 – Intensity
//5 – Strobe
//6 – Fan Control
//7 – n/a
//8 – Plus 7
//Control on/off
//9 – Red
//10 – Lime
//11 – Amber
//12 – Green
//13 – Cyan
//14 – Blue
//15 – Indigo
//turn on 1st Red light 9
DMX.write(9, 255);
//turn on 2nd Greenlight 12
DMX.write(27, 255);
delay (random(3000,8000);
//delay randomly from 3-8 seconds
//turn off 1st & 2nd lights
DMX.write(9, 0);
DMX.write(27,0);
//turn on 3rd blue light
DMX.write(44,255);
delay (random(3000,5000);
DMX.endTransmission();
}
}
//we can play with the effects for the 1st and 2nd lights.
// 1 – Hue (coarse)
// 2 – Hue (fine)
// 3 – Saturation
// 4 – Intensity
// 5 – Strobe
// 6 – Fan Control
//on the Uno, you will not be able to use the Serial Monitor for debugging messages
//because the ArduinoRS485 library takes over the hardware serial port.
//Check this on the Every too
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
//sensor connected to port 8
const int sensorPin = 0;
//connecting to 3 lights, so universeSize is 6*3
const int universeSize = 18;
//initialize delay size (for step fading)
int lastFadeTime = 0; //last time I made a fade change
int fadeDelay = 30; //delay between steps
//initialize count as timer, counting the duration of pressure being applied
int count;
//initialize waiting duration
int countdown;
//initalize pressure to store voltage reading from the pressure sensor
int pressure;
const int pThreshold = 1000;
//initialize data structure for lights for HSL mode
int light1[] = {0,0,0,0,0,255};
int light2[] = {127,0,0,0,0,255};
int light3[] = {0,0,0,0,0,255};
int hueFade[] = {30,30,0};
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
//set timer's count to 0
count = 0;
//initialize duration
countdown = randomDuration(5000,8000);
//if initialization fails
if(!DMX.begin(universeSize)){
Serial.println("Failed to initialize DMX!");
//if true, wait forever
while (true);
}
}
void loop() {
//millis() increments like a clock
if (millis() - lastFadeTime > fadeDelay){
DMX.beginTransmission();
for (int i = 1; i < 7; i++){ //write to lights using values in the array
DMX.write(i, light1[i-1]);
DMX.write(i*2, light2[i-1]);
DMX.write(i*3, light3[i-1]);
}
if (count >= countdown){ //when timer count reaches countdown
light1[3] = 0; //turn off light1
light2[3] = 0; //turn off light2
light3[3] = 255; //turn on light3
}
else { //when timer hasn't reached countdown
if (analogRead(sensorPin) > pThreshold){ //when pressure level is above threshold
count = count + fadeDelay; //add to timer count
light1[0] += hueFade[0]; //animate light1 by fading Hue linearly
light2[0] += hueFade[1]; //animate light2 by fading Hue linearly
light1[2] = 255; //set saturation to 255
light2[2] = 255; //set saturation to 255
if (light1[0] <= 0 || light1[0] >= 255){
hueFade[0] = -hueFade[0];
}
if (light2[0] <= 0 || light2[0] >= 255){
hueFade[1] = -hueFade[1];
}
}
else{ //when pressure level is below threshold
light1[2] = 0; //set saturation to 0
light2[2] = 0; //set saturation to 0
}
}
lastFadeTime = millis();
}
}
int randomDuration(int a, int b){
return random(a, b);
}
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
int currentLevel = 255;
int change = 1;
const int resolution = 10;
const int steps = pow(2, resolution);
int levelTable[steps]; // pre-calculated PWM levels
void setup() {
Serial.begin(9600);
// pre-calculate the PWM levels from the formula:
fillLevelTable();
}
void loop() {
// decrease or increase by 1 point each time
// if at the bottom or top, change the direction:
if (currentLevel <= 0 || currentLevel >= steps) {
change = -change;
}
currentLevel += change;
//PWM output the result:
analogWrite(5, levelTable[currentLevel]);
delay(10);
Serial.println(levelTable[currentLevel]);
}
void fillLevelTable() {
// set the range of values:
float maxValue = steps;
// iterate over the array and calculate the right value for it:
for (int l = 0; l <= maxValue; l++) {
// map input to a 0-179 range:
float angle = map(l, 0, maxValue, 0, 179);
/* here's the explanation of the calculation:
// convert to radians:
float result = angle * PI/180;
// now add PI/2 to offset by 90 degrees:
result = result + PI/2;
// get the sine of that:
result = sin(result);
// now you have -1 to 1. Add 1 to get 0 to 2:
result = result + 1;
// multiply to get 0-255:
result = result * 127.5;
*/
//here it all is in one line:
float lightLevel = (sin((angle * PI / 180) + PI / 2) + 1) * (steps/2);
levelTable[l] = lightLevel;
}
}
//1 – Hue (coarse)
// 2 – Hue (fine)
// 3 – Saturation
// 4 – Intensity
// 5 – Strobe
// 6 – Fan Control
//on the Uno, you will not be able to use the Serial Monitor for debugging messages
//because the ArduinoRS485 library takes over the hardware serial port.
//Check this on the Every too
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
//sensor connected to port 8
const int sensorPin = 0;
//connecting to 3 lights, so universeSize is 6*3
const int universeSize = 9;
//initialize delay size (for step fading)
int lastFadeTime = 0; //last time I made a fade change
int fadeDelay = 30; //delay between steps
//initialize count as timer, counting the duration of pressure being applied
int count;
//initialize waiting duration
int countdown;
//initalize pressure to store voltage reading from the pressure sensor
int pressure;
const int pThreshold = 500;
//initialize data structure for lights, for HSL mode
int light1[] = {0,0,0,255,0,255};
int light2[] = {0,0,0};
int hueFade[] = {30,0};
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
//set timer's count to 0
count = 0;
//initialize duration
countdown = randomDuration(5000,8000);
//if initialization fails
if(!DMX.begin(universeSize)){
Serial.println("Failed to initialize DMX!");
//if true, wait forever
while (true);
}
}
void loop() {
pressure= analogRead(sensorPin);
//millis() increments like a clock
if (millis() - lastFadeTime > fadeDelay){
DMX.beginTransmission();
for (int i = 1; i < 10; i++){ //write to lights using values in the array
DMX.write(i, light1[i-1]);
if (i > 6){
DMX.write(i-6, light2[i-7]);
}
DMX.endTransmission();
if (count >= countdown){ //when timer count reaches countdown
light1[3] = 0; //turn off light1
light2[0] = 255; //turn on light3
}
else { //when timer hasn't reached countdown
if (analogRead(sensorPin) > pThreshold){ //when pressure level is above threshold
count = count + fadeDelay; //add to timer count
light1[0] += hueFade[0]; //animate light1 by fading Hue linearly
light1[2] = 255; //set saturation to 255
if (light1[0] <= 0 || light1[0] >= 255){
hueFade[0] = -hueFade[0];
}
}
else{ //when pressure level is below threshold
light1[2] = 0; //set saturation to 0
}
}
lastFadeTime = millis();
}
//Serial.println(pressure);
Serial.println(light1[3]);
}
int randomDuration(int a, int b){
return random(a, b);
}
//1 – Hue (coarse)
// 2 – Hue (fine)
// 3 – Saturation
// 4 – Intensity
// 5 – Strobe
// 6 – Fan Control
//on the Uno, you will not be able to use the Serial Monitor for debugging messages
//because the ArduinoRS485 library takes over the hardware serial port.
//Check this on the Every too
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
//sensor connected to port 8
const int sensorPin = 0;
//connecting to 3 lights, so universeSize is 6*3
const int universeSize = 9;
//initialize delay size (for step fading)
int lastFadeTime = 0; //last time I made a fade change
int fadeDelay = 30; //delay between steps
//initialize count as timer, counting the duration of pressure being applied
int count;
//initialize waiting duration
int countdown;
//initalize pressure to store voltage reading from the pressure sensor
int pressure;
const int pThreshold = 800;
//initialize data structure for lights, for HSL mode
int light1[] = {0,0,0,255,0,255};
int light2[] = {0,0,0};
//int light3[] = {0,0,0,0,0,255};
int hueFade[] = {1,0};
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
//set timer's count to 0
count = 0;
//initialize duration
countdown = 8000;
//randomDuration(5000,8000);
//if initialization fails
if(!DMX.begin(universeSize)){
Serial.println("Failed to initialize DMX!");
//if true, wait forever
while (true);
}
}
void loop() {
pressure= analogRead(sensorPin);
//millis() increments like a clock
if (millis() - lastFadeTime > fadeDelay){
DMX.beginTransmission();
for (int i = 1; i < 10; i++){ //write to lights using values in the array
DMX.write(i, light1[i-1]);
if(i>6){
DMX.write(i, light2[i-7]);
}
DMX.endTransmission();
if (count >= countdown){ //when timer count reaches countdown
light1[3] = 0; //turn off light1
light2[0] = 255; //turn on light2
//light3[3] = 255; //turn on light3
}
else { //when timer hasn't reached countdown
if (analogRead(sensorPin) > pThreshold){ //when pressure level is above threshold
count = count + fadeDelay; //add to timer count
light1[0] += hueFade[0]; //animate light1 by fading Hue linearly
//light2[0] += hueFade[1]; //animate light2 by fading Hue linearly
light1[2] = 255; //set saturation to 255
// light2[2] = 255; //set saturation to 255
if (light1[0] <= 0 || light1[0] >= 255){
hueFade[0] = -hueFade[0];
}
}
else{ //when pressure level is below threshold
light1[2] = 0;
light1[3]= 255; //set saturation to 0
// light2[2] = 0; //set saturation to 0
}
}
lastFadeTime = millis();
}
//Serial.println(pressure);
Serial.println(light1[4]);
//Serial.println(analogRead(A0));
}
//int randomDuration(int a, int b){
// return random(a, b);
}
//1 – Hue (coarse)
// 2 – Hue (fine)
// 3 – Saturation
// 4 – Intensity
// 5 – Strobe
// 6 – Fan Control
//on the Uno, you will not be able to use the Serial Monitor for debugging messages
//because the ArduinoRS485 library takes over the hardware serial port.
//Check this on the Every too
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
//sensor connected to port 8
const int sensorPin = 0;
//connecting to 2 lights, so universeSize is 6+3
const int universeSize = 512;
//initialize delay size (for step fading)
int lastFadeTime = 0; //last time I made a fade change
int fadeDelay = 30; //delay between steps
//initialize count as timer, counting the duration of pressure being applied
int count;
//initialize waiting duration
int countdown;
//initalize pressure to store voltage reading from the pressure sensor
int pressure;
const int pThreshold = 500;
//initialize data structure for lights, for HSL mode
int light2[] = { 0, 0, 0, 255, 0, 255 };
int light1[] = { 0, 0, 0 };
int hueFade[] = { 30, 0 };
int randomDuration(int a, int b) {
return random(a, b);
}
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
//set timer's count to 0
count = 0;
//initialize duration
countdown = randomDuration(5000, 8000);
//if initialization fails
if (!DMX.begin(universeSize)) {
Serial.println("Failed to initialize DMX!");
//if true, wait forever
while (true)
;
}
}
void loop() {
pressure = analogRead(sensorPin);
if (count >= countdown) { //when timer count reaches countdown
light2[3] = 0; //turn off light1
light1[0] = 255; //turn on light3
}
else { //when timer hasn't reached countdown
if (pressure > pThreshold) { //when pressure level is above threshold
count = count + fadeDelay; //add to timer count
light2[0] += hueFade[0]; //animate light1 by fading Hue linearly
light2[2] = 255; //set saturation to 255
if (light2[0] <= 0 || light2[0] >= 255) {
hueFade[0] = -hueFade[0];
}
} else { //when pressure level is below threshold
light2[2] = 0; //set saturation to 0
}
}
//millis() increments like a clock
if (millis() - lastFadeTime > fadeDelay) {
DMX.beginTransmission();
for (int i = 1; i < 10; i++) { //write to lights using values in the array
DMX.write(i, light1[i - 1]);
if (i > 3) {
DMX.write(i - 3, light2[i - 4]);
}
}
DMX.endTransmission();
lastFadeTime = millis();
}
//Serial.println(pressure);
// Serial.println(DMX.read(1));
}
//1 – Hue (coarse)
// 2 – Hue (fine)
// 3 – Saturation
// 4 – Intensity
// 5 – Strobe
// 6 – Fan Control
#include <ArduinoRS485.h>
#include <ArduinoDMX.h>
//sensor connected to port 8
const int sensorPin = 0;
//connecting to 2 lights, so universeSize is 6+3
const int universeSize = 512;
//initialize delay size (for step fading)
int lastFadeTime = 0; //last time I made a fade change
int fadeDelay = 30; //delay between steps
//initialize count as timer, counting the duration of pressure being applied
int count;
//initialize waiting duration
int stepDelay;
int lastSensor;
int currentSensor;
int lastStepTime;
int lastSend = 0;
//initalize pressure to store voltage reading from the pressure sensor
int pressure;
const int threshold = 500;
//initialize data structure for lights, for HSL mode
int light2[] = { 0, 0, 0, 255, 0, 255 };
int light1[] = { 0, 0, 0 };
int hueFade[] = { 30, 0 };
int randomDuration(int a, int b) {
return random(a, b);
}
void setup() {
// put your setup code here, to run once:
stepDelay = randomDuration(3000, 5000);
}
void loop() {
// at the instant the sensor changes from
// below threshold to above, start counting
if (currentSensor > lastSensor + threshold) {
lastStepTime = millis();
}
// save currentSensor for comparison next time:
lastSensor = currentSensor;
// when the plate isn't being stepped on
// give off white light
light2[2] = 0;
if (currentSensor > threshold) {
light2[0] += hueFade[0]; // animate light1 by fading Hue linearly
light2[2] = 255; // set saturation to 255
if (light2[0] <= 0 || light2[0] >= 255) { // continiously shifts hue
hueFade[0] = -hueFade[0];
}
// if the step delay has passed AND the sensor is above the threshold,
// take action
if (millis() - lastStepTime > stepDelay) {
// take action
light2[3] = 0; //turn off light2
light1[0] = 255; //turn on light1
// change the value of light1 intensity
// and light2 intensity
}
}
// send to the lights every 100ms:
if (millis() - lastSend > 100) {
DMX.beginTransmission();
DMX.write(1, light2[0]);
DMX.write(4, light1[0]);
DMX.write(6, light2[2]);
DMX.write(7, light2[3]);
DMX.endTransmission();
lastSend = millis();
}
}