adding changes after liminar performance - arduino!
parent
2109e102a5
commit
8a2353a6ad
@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
#include <TimerOne.h> // Include Timer1 library
|
||||||
|
#include <SimpleMessageSystem.h> // Include SimpleMessageSystem library
|
||||||
|
|
||||||
|
// This is programmed for an Arduino Mega controlling lights from outs 22+
|
||||||
|
int AC_pin_offset = 22; // lowest out for lights
|
||||||
|
int dims[18]; // dimmer values
|
||||||
|
unsigned char clock_tick; // variable for Timer1
|
||||||
|
unsigned int delay_time = 50;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
for(int i = 0; i < 18; i++){
|
||||||
|
dims[i] = 110;
|
||||||
|
// Set the pins to the triacs as outputs (using outs 0 - 17)
|
||||||
|
pinMode(AC_pin_offset + i, OUTPUT);
|
||||||
|
};
|
||||||
|
attachInterrupt(0, zero_crosss_int, RISING);
|
||||||
|
Timer1.initialize(65); // set a timer of length 100 microseconds for 50Hz or 83 microseconds for 60Hz;
|
||||||
|
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is the dimmer
|
||||||
|
void timerIsr() {
|
||||||
|
clock_tick++;
|
||||||
|
for(int i = 0; i < 18; i++) {
|
||||||
|
if (dims[i] == clock_tick) {
|
||||||
|
digitalWrite(AC_pin_offset + i, HIGH); // triac on
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// function to be fired at the zero crossing to dim the light
|
||||||
|
void zero_crosss_int() {
|
||||||
|
clock_tick=0;
|
||||||
|
for(int i = 0; i < 18; i++){
|
||||||
|
digitalWrite(AC_pin_offset + i, LOW); // triac Off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
int light = 0;
|
||||||
|
int val = 0;
|
||||||
|
// Checks to see if the message is complete and erases any previous messages
|
||||||
|
if (messageBuild() > 0) {
|
||||||
|
light = messageGetInt();
|
||||||
|
val = messageGetInt();
|
||||||
|
dims[light] = val;
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue