Page : | [ 1 ] | [ 2 ] | [ 3 ] |
First I controlled it with an arduino and here's the software for that. I also controlled it from an ESP8266 module.
In this program I skip every 2nd zero cross detection and just wait out a poredetermined amount of time to fire it again. This seemed to work better but I'll certainly need to revisit this in the future when I make a "real" version of this (which would include a varistor and fuse for safety and protection)
#define ZERO 2
#define GATE 3
#define GATE_DELAY 9
/* range 0 - 255 : 0 = off 255 = on */
volatile uint8_t dim = 127;
volatile uint8_t skip = 0;
void setup() {
pinMode(ZERO, INPUT_PULLUP);
pinMode(GATE, OUTPUT);
attachInterrupt(digitalPinToInterrupt(ZERO), dimmer, RISING);
Serial.begin(9600);
}
void loop() {
/* dim test */
int i=0;
for (;i < 256; i++){
dim = i;
delay(100);
Serial.print("dim value: ");
Serial.println(i);
}
for (;i >= 0; i--){
dim = i;
delay(100);
Serial.print("dim value: ");
Serial.println(i);
}
}
void dimmer() {
if (skip == 0){
dim = 180;
/* (1000ms / 120hz) = 8.33 */
float waitMillis = (8.33 / 255) * (255 - dim);
uint16_t waitMicros = (uint16_t)(waitMillis * (float)1000);
delayMicroseconds(waitMicros);
digitalWrite(GATE, HIGH);
delayMicroseconds(GATE_DELAY);
digitalWrite(GATE, LOW);
delayMicroseconds(8330 - GATE_DELAY);
digitalWrite(GATE, HIGH);
delayMicroseconds(GATE_DELAY);
digitalWrite(GATE, LOW);
skip = 1;
} else {
skip = 0;
}
}
(Page 3 of 3) | ||