making everything work with homemade circut and krida premade
This commit is contained in:
parent
96d3bfad77
commit
9edd93a58b
|
|
@ -1,22 +1,24 @@
|
||||||
|
|
||||||
#include <TimerOne.h> // Include Timer1 library
|
#include <TimerOne.h> // Include Timer1 library
|
||||||
#include <SimpleMessageSystem.h> // Include SimpleMessageSystem library
|
|
||||||
|
|
||||||
// This is programmed for an Arduino Mega controlling lights from outs 22+
|
// Pin outputs for the 18 lights
|
||||||
int AC_pin_offset = 22; // lowest out for lights
|
int AC_pin_offsets[18] = {22, 24, 26, 28, 30, 23, 25, 27, 29, 32, 34, 36, 38, 31, 33, 35, 37, 39};
|
||||||
|
int freq = 50; // 50 for EU and 60 for US
|
||||||
int dims[18]; // dimmer values
|
int dims[18]; // dimmer values
|
||||||
unsigned char clock_tick; // variable for Timer1
|
unsigned char clock_tick; // variable for Timer1
|
||||||
|
char incomingByte;
|
||||||
|
int val = 0;
|
||||||
|
int light = 0;
|
||||||
|
int delim = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
for(int i = 0; i < 18; i++){
|
for(int i = 0; i < 18; i++){
|
||||||
dims[i] = 256;
|
dims[i] = 215;
|
||||||
// Set the pins to the triacs as outputs (using outs 0 - 17)
|
pinMode(AC_pin_offsets[i], OUTPUT);
|
||||||
pinMode(AC_pin_offset + i, OUTPUT);
|
|
||||||
};
|
};
|
||||||
attachInterrupt(0, zero_crosss_int, RISING);
|
attachInterrupt(0, zero_crosss_int, RISING);
|
||||||
// for resoution of 128 steps, set timer so 33 microseconds for 60 Hz or 39 for 50 Hz
|
Timer1.initialize(1000000 / (freq * 2) / 256); // 8 bit control
|
||||||
Timer1.initialize(39);
|
|
||||||
Timer1.attachInterrupt(timerIsr); // attach the service routine here
|
Timer1.attachInterrupt(timerIsr); // attach the service routine here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +27,9 @@ void timerIsr() {
|
||||||
clock_tick++;
|
clock_tick++;
|
||||||
for(int i = 0; i < 18; i++) {
|
for(int i = 0; i < 18; i++) {
|
||||||
if (dims[i] == clock_tick) {
|
if (dims[i] == clock_tick) {
|
||||||
digitalWrite(AC_pin_offset + i, HIGH); // triac on
|
digitalWrite(AC_pin_offsets[i], HIGH); // triac on
|
||||||
|
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33, for 50Hz use 10)
|
||||||
|
digitalWrite(AC_pin_offsets[i], LOW); //triac off
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -33,18 +37,18 @@ void timerIsr() {
|
||||||
// function to be fired at the zero crossing to dim the light
|
// function to be fired at the zero crossing to dim the light
|
||||||
void zero_crosss_int() {
|
void zero_crosss_int() {
|
||||||
clock_tick=0;
|
clock_tick=0;
|
||||||
for(int i = 0; i < 18; i++){
|
|
||||||
digitalWrite(AC_pin_offset + i, LOW); // triac Off
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(){
|
void loop(){
|
||||||
int light = 0;
|
if (Serial.available() > 0) { // something came across serial
|
||||||
int val = 0;
|
while(1) {
|
||||||
// Checks to see if the message is complete and erases any previous messages
|
incomingByte = Serial.read();
|
||||||
if (messageBuild() > 0) {
|
if(incomingByte == -1) {break;};
|
||||||
light = messageGetInt();
|
if(incomingByte < 0) {val = 256 + incomingByte;} else {val = incomingByte;};
|
||||||
val = messageGetInt();
|
if(val == 253) {delim = 1; continue;};
|
||||||
dims[light] = val;
|
if(val == 254) {delim = 0; continue;};
|
||||||
}
|
if(delim == 0) light = val;
|
||||||
|
if(delim == 1) dims[light] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,21 @@ projectionWin.view.keyDownAction = { |doc, char, mod, unicode, keycode, key|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect arduino; edit first arg / port to match index or name of port: SerialPort.listDevices
|
// Connect arduino; edit first arg / port to match index or name of port: SerialPort.listDevices
|
||||||
if(~arduino == 1, { arduino_port = SerialPort( 0, 115200) }, {});
|
if(~arduino == 1, { arduino_port = SerialPort("/dev/ttyACM0", 115200);
|
||||||
|
r= Routine({
|
||||||
|
var byte, str, res;
|
||||||
|
99999.do{|i|
|
||||||
|
byte = arduino_port.read;
|
||||||
|
if(byte==13, {
|
||||||
|
(str).postln;
|
||||||
|
str = "";
|
||||||
|
},
|
||||||
|
{
|
||||||
|
str= str++byte.asAscii;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}).play;
|
||||||
|
}, {});
|
||||||
|
|
||||||
// Get control signals from SynthDef
|
// Get control signals from SynthDef
|
||||||
osc_func = OSCFunc.new({arg msg, time; brightness[msg[2]] = msg[3]; },'/tr', s.addr);
|
osc_func = OSCFunc.new({arg msg, time; brightness[msg[2]] = msg[3]; },'/tr', s.addr);
|
||||||
|
|
@ -52,24 +66,28 @@ projectionWin.drawFunc = {
|
||||||
};
|
};
|
||||||
projectionWin.refresh;
|
projectionWin.refresh;
|
||||||
|
|
||||||
|
|
||||||
// Refresh function
|
// Refresh function
|
||||||
refresh_func = { while { true } {
|
refresh_func = { while { true } {
|
||||||
// updateProjection
|
// updateProjection
|
||||||
projectionWin.refresh;
|
projectionWin.refresh;
|
||||||
|
|
||||||
// updateArduino
|
|
||||||
if(~arduino == 1, {
|
if(~arduino == 1, {
|
||||||
// set min and max Brightness between 0 and 1 depending on wattage of light
|
// set min and max Brightness between 0 and 1 depending on wattage of light
|
||||||
// it is best to keep the min slightly higher than 0 to keep the light from turning completely off
|
// it is best to keep the min slightly higher than 0 to keep the light from turning completely off
|
||||||
{|i| var minBrightness = 0.15, maxBrightness = 0.85;
|
{|i| var minBrightness = 0.15, maxBrightness = 0.85;
|
||||||
arduino_port.putAll(i.asString);
|
arduino_port.put(i);
|
||||||
arduino_port.put(Char.space);
|
arduino_port.put(253);
|
||||||
arduino_port.putAll((((brightness[i] * (maxBrightness - minBrightness) + minBrightness) - 1).abs * 256)
|
//if(brightness[0] < 0
|
||||||
.trunc.asString);
|
arduino_port.put(((((brightness[i] * (maxBrightness - minBrightness)) + minBrightness) - 1).abs * 256).asInteger);
|
||||||
arduino_port.put(Char.space);
|
arduino_port.put(254);
|
||||||
arduino_port.put(13);
|
//arduino_port.put(254);
|
||||||
} ! 18 }, {});
|
} ! 18 }, {});
|
||||||
|
|
||||||
// delay
|
// delay
|
||||||
30.reciprocal.wait; } };
|
30.reciprocal.wait; } };
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//Char.space.asInt
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue