http://www.instructables.com/id/3-channel-Dimmerfader-for-Arduino-or-other-microco/step2/3-channel-Dimmerfader-for-Arduino-or-other-microco/
http://br-arduino.org/2016/04/arduino-interrupcoes-timer1.html
Lista de Materiais:
IDE Arduino 1.0.6
1x Board Arduino MEGA 2560
1x Cabo USB-A male to USB-B male
2x Lâmpada incandescente 40w 127Vac
2x Bocal para lâmpada
1x Shield Mega Relay & Dimmer V.2.1
Montagem:
Firmware 01:
int AC_LOAD = 5; // Output to Opto Triac pin
int dimming; // Dimming level (0-128) 0 = ON, 128 = OFF
//*******************************************************************************
void setup(){
pinMode(AC_LOAD, OUTPUT);
attachInterrupt(0, zero_crosss_int, RISING);
}
//*******************************************************************************
void zero_crosss_int() {
int dimtime = (65*dimming);
delayMicroseconds(dimtime); // Off cycle
digitalWrite(AC_LOAD, HIGH); // triac firing
delayMicroseconds(8.33); // triac On propogation delay
digitalWrite(AC_LOAD, LOW); // triac Off
}
//*******************************************************************************
void loop(){
dimming = 100; }
Firmware 02:
#include <TimerOne.h>
#define PINS 2
//*******************************************************************************
volatile int pinCount[PINS];
volatile boolean zero_cross=0;
int AC_pins[] = {4,5};
int AC_dim[PINS];
int freqStep = 65;
//*******************************************************************************
void setup() {
for(int a=0; a < PINS; a++) {
pinMode(AC_pins[a],OUTPUT);
pinCount[a] = 0;
AC_dim[a] = 0;
}
attachInterrupt(0, zero_cross_detect, FALLING);
Serial.begin(9600);
Timer1.initialize(freqStep);
Timer1.attachInterrupt(dim_check, freqStep);
}
//*******************************************************************************
void zero_cross_detect() {
zero_cross = 1;
}
//*******************************************************************************
void dim_check() {
if(zero_cross == 1) {
for(int a=0; a < PINS; a++) {
if(pinCount[a] >= AC_dim[a]) {
digitalWrite(AC_pins[a], HIGH);
delayMicroseconds(5);
digitalWrite(AC_pins[a], LOW);
pinCount[a] = 0;
zero_cross = 0;
} else {
pinCount[a]++;
}
}
}
}
//*******************************************************************************
void loop() {
for(int i=0; i<127; i ++) {
for(int a=0; a < PINS; a++) {
int ii = i+42;
if(ii > 127) ii -= 127;
AC_dim[a] = ii;
}
delay(50);
}
}
Download: TimerOne.h
Nenhum comentário:
Postar um comentário