need help


i made dimmer circuit.its working when control using ir sensor not working:(
plz me
*/

#include <irremote.h>
#include <timerone.h> // avaiable http://www.arduino.cc/playground/code/timer1

const int recv_pin = 6;

irrecv irrecv(recv_pin);
decode_results results;
unsigned long last = millis();

// hex code remote control buttons
#define power 0x10efd827
#define 0x10eff807
#define b 0x10ef7887
#define c 0x10ef58a7
#define 0x10efa05f
#define down 0x10ef00ff
#define left 0x10ef10ef
#define right 0x10ef807f
#define select 0x10ef20df



volatile int i=0; // variable use counter of dimming steps. volatile since passed between interrupts
volatile boolean zero_cross=0; // flag indicate have crossed zero
int ac_pin = 3; // output opto triac

int dim2 = 0; // led control
int dim = 128; // dimming level (0-128) 0 = on, 128 = 0ff
int pas = 8; // step count;
int freqstep = 65; // delay-per-brightness step in microseconds. allows 128 steps
// if using 60 hz grid frequency set 65


void setup() { // begin setup
serial.begin(9600);
pinmode(ac_pin, output); // set triac pin output
irrecv.enableirin(); // start ir receiver

attachinterrupt(0, zero_cross_detect, rising); // attach interupt pin 2 (interupt 0) 0 cross detection
timer1.initialize(freqstep); // initialize timerone library freq need
timer1.attachinterrupt(dim_check, freqstep); // go dim_check procedure every 75 (50hz) or 65 (60hz)
// use timerone library attach interrupt

}

void zero_cross_detect() {
zero_cross = true; // set flag dim_check function 0 cross has occured
i=0; // stepcounter 0.... start new cycle
digitalwrite(ac_pin, low);
}

// turn on triac @ appropriate time
// arrive here every 75 (65) us
// first check if flag has been set
// check if counter 'i' has reached dimming level
// if so.... switch on triac , reset counter
void dim_check() {
if(zero_cross == true) {
if(i>=dim) {
digitalwrite(ac_pin, high); // turn on light
i=0; // reset time step counter
zero_cross=false; // reset 0 cross detection flag
}
else {
i++; // increment time step counter
}
}
}

void test_dimmer(){
dim+=inc;
if((dim_ac>=128) || (dim_ac<=0))
inc*=-1;
delay(18);
}


void loop() {

if (irrecv.decode(&results))
{

if (results.value == up){
// if it's been @ least 1/4 second since last
if (millis() - last > 250) {
serial.print("dimming --> ");
serial.println(dim);
if (dim<127)
{
dim = dim + pas;
if (dim>127){
dim=128;
}
}
}
}

if (results.value == down ){
// if it's been @ least 1/4 second since last
if (millis() - last > 250) {
serial.print("dimming down --> ");
serial.println(dim);

if (dim>5)
{
dim = dim - pas;
if (dim<0){
dim=0;
}
}
}
}
} // loop

there's not dimming @ all, ir receiver doesnt work code..

do think can me?

thank sooo much!

marc:)

what see when print results.value ?


Arduino Forum > Using Arduino > Programming Questions > need help


arduino

Comments