Hi, I'm new. Bought a 4-channel Krida Triac Dimmer and an Uno and HC-5 module. I would like to use for 2 circuits of Led lamps in new pantry. I couldn't download a photo, but will keep at it. I was able to put Krida supplied code into IDE and have that below. I have it working as advertised, but need to change program for my application.
The plan is to have the lights come on to the desired level, and stay on while the power is on. Once I close door, both the Arduino and the dimmer will have the power cut off. When the pantry door opens, mains ac is switched on to both the Arduino's power adapter, and to the high-power side of the dimmer board. Only two channels are used on the dimmer.
Here is what I'd like to modify:
[code]
// This is me trying to make imported Krida Bluetooth 50hz work for 60hz. Don't know why it's called secondtry. Here goes.
//
// Testing sketch for 50Hz !!!
//
// Bluetooth Module HC-05, Speed 9600kbps
//
// How to connect dimmer and hc-05 modules to Arduino UNO board
//
// Dimmer Arduino
// | |
// GND GND
// VCC 5V
// SYNC DIGITAL.3
// CH1 DIGITAL.7
// CH2 DIGITAL.6
// CH3 DIGITAL.5
// CH4 DIGITAL.4
//
// HC-05 Arduino UNO
// | |
// GND GND
// VCC 5V
// TX RX (DIGITAL.0)
#include <TimerOne.h> // download this library from arduino.cc
unsigned char channel_1 = 7; // Output to Opto Triac pin, channel 1
unsigned char channel_2 = 6; // Output to Opto Triac pin, channel 2
unsigned char channel_3 = 5; // Output to Opto Triac pin, channel 3
unsigned char channel_4 = 4; // Output to Opto Triac pin, channel 4
unsigned char CH1, CH2, CH3, CH4;
unsigned char i=0;
unsigned int delay_time=2500; // delay ms or SPEED
unsigned char clock_tick; // variable for Timer1
int incomingByte = 0;
int mas[3];
void setup() {
Serial.begin(9600);
pinMode(channel_1, OUTPUT);// Set AC Load pin as output
pinMode(channel_2, OUTPUT);// Set AC Load pin as output
pinMode(channel_3, OUTPUT);// Set AC Load pin as output
pinMode(channel_4, OUTPUT);// Set AC Load pin as output
attachInterrupt(1, zero_crosss_int, RISING);
Timer1.initialize(83); // set a timer of length 100 microseconds for 50Hz or 83 microseconds for 60Hz;
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
CH1=CH2=CH3=CH4=95; // WHEN ARDUINO START, ALL LIGHT OFF (95 - FULLY OFF ; 5 - FULLY ON) !!!
}
void timerIsr()
{
clock_tick++;
if (CH1==clock_tick)
{
digitalWrite(channel_1, HIGH); // triac firing
delayMicroseconds(8.33); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_1, LOW); // triac Off
}
if (CH2==clock_tick)
{
digitalWrite(channel_2, HIGH); // triac firing
delayMicroseconds(8.33); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_2, LOW); // triac Off
}
if (CH3==clock_tick)
{
digitalWrite(channel_3, HIGH); // triac firing
delayMicroseconds(8.33); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_3, LOW); // triac Off
}
if (CH4==clock_tick)
{
digitalWrite(channel_4, HIGH); // triac firing
delayMicroseconds(8.33); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(channel_4, LOW); // triac Off
}
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
// Every zerocrossing interrupt: For 50Hz (1/2 Cycle) => 10ms ; For 60Hz (1/2 Cycle) => 8.33ms
// 10ms=10000us , 8.33ms=8330us
clock_tick=0;
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte=='X')
{
mas[0]=Serial.read();
mas[1]=Serial.read();
mas[2]=Serial.read();
Serial.flush();
}
if (mas[0]=='A') { if(mas[1]>=0) {CH1=mas[1]; CH1=100-CH1; if (CH1<5) {CH1=5;} if (CH1>95) {CH1=95;}}}
if (mas[0]=='B') { if(mas[1]>=0) {CH2=mas[1]; CH2=100-CH2; if (CH2<5) {CH2=5;} if (CH2>95) {CH2=95;}}}
if (mas[0]=='C') { if(mas[1]>=0) {CH3=mas[1]; CH3=100-CH3; if (CH3<5) {CH3=5;} if (CH3>95) {CH3=95;}}}
if (mas[0]=='D') { if(mas[1]>=0) {CH4=mas[1]; CH4=100-CH4; if (CH4<5) {CH4=5;} if (CH4>95) {CH4=95;}}}
}
Serial.print("CH1 ");Serial.print(CH1);
Serial.print("; CH2 ");Serial.print(CH2);
Serial.print("; CH3 ");Serial.print(CH3);
Serial.print("; CH4 ");Serial.println(CH4);
}
[/code]`Preformatted text`
What I need instead is code which performs differently in two respects.
I do not need to use a phone app to turn on and dim lights. Far better to have the brightness levels written into the program. They will be different for each channle, but will not vary after dimmer is installed. How can I substitute constants for the target brightness in this code?
I'd like the two channels to ramp up to the set brightness level. In some of the trial and error I've been at the brightness increased incrementally each loop, and I could adjust a delay which effected the fade rate. That was in a different sketch, using a different library, and I'd like to do that here.
I know it's alot. Perhaps I can take these one at a time. First lose all the code for the blutooth and the unnecessary channels, and identfy where and how to write in the target brightness values.
Thanks for having a look.
