stephanschulz
Well-known member
i am working on a project for which i need to dim an AC light bulb.
i purchased this board and with the code below the dimming works great, when using an arduino uno.
http://www.inmojo.com/store/inmojo-market/item/digital-ac-dimmer-module-lite-v.2/
but when i try using the code with the teensy 3.0 the light flickers.
i also tried using an interrupt on pin 2, every time a zero crossing happens, and have it call zeroCross()
attachInterrupt(2, zero_crosss_int, RISING);
still flickers.
what might the difference be here, between the arduino and the teensy.
thanks.
i purchased this board and with the code below the dimming works great, when using an arduino uno.
http://www.inmojo.com/store/inmojo-market/item/digital-ac-dimmer-module-lite-v.2/
but when i try using the code with the teensy 3.0 the light flickers.
Code:
//http://www.youtube.com/watch?v=ztXRjyCQxlE
//backyard amusement
int redPin = 3;
int zeroPin = 2;
int minDimValue = 0; //0 is brightness value
int maxDimValue = 340; //550; //550 is lowest brihtness value
int dimValue = maxDimValue;
int dimStep = 5;
int dimDir = -1;
long crosstime = 0;
long currentcycle = 0;
unsigned long timer = 0;
boolean bNewCycle = true;
boolean bAutoFade = true;
boolean bOn = true;
void setup(){
Serial.begin(9600);
Serial.println("ac_dimmer_youtube_4");
pinMode(redPin, OUTPUT);
pinMode(zeroPin,INPUT);
}
void loop(){
if (Serial.available()){
handleInput(Serial.read());
}
if(digitalRead(zeroPin)){
//Serial.println("read");
crosstime = micros();
}
zeroCross();
if(bAutoFade){
if(micros() - timer > 1500){
timer = micros();
dimValue += dimDir;
if(dimValue >= maxDimValue){
dimDir = -1;
dimValue = maxDimValue;
}
if(dimValue <= minDimValue){
// delay(2000);
dimDir = 1;
dimValue = minDimValue;
}
}
}
}
void zeroCross(){
if(bOn){
if(micros() - crosstime < 8200){
currentcycle = micros() - crosstime;
if(currentcycle > (dimValue * 16)) digitalWrite(redPin,1);
digitalWrite(redPin, 0);
}
} else{
digitalWrite(redPin, 0);
}
}
i also tried using an interrupt on pin 2, every time a zero crossing happens, and have it call zeroCross()
attachInterrupt(2, zero_crosss_int, RISING);
still flickers.
what might the difference be here, between the arduino and the teensy.
thanks.