Newbie
Join Date: Jun 2012
Posts: 2

LinkBack  Thread Tools  Display Modes 
Sponsored Links  
Advertisement


#include <TimerThree.h> const int kChan0Pin = 5; // Channel 0 Pin const int kChan1Pin = 2; // Channel 1 Pin const int kChan2Pin = 3; // Channel 2 Pin
const int kDayState[] = { 1023, 1023, 1023 }; // daytime LED state const int kNightState[] = { 0, 0, 0 }; // nighttime LED state
int state_chan1, state_chan2, state_chan3;
void fader(long start_time, const int start_state[], const int end_state[], int out[3]) { float per_second_delta_0 = (float) (end_state[0]start_state[0])/kFadeDuration; float per_second_delta_1 = (float) (end_state[1]start_state[1])/kFadeDuration; float per_second_delta_2 = (float) (end_state[2]start_state[2])/kFadeDuration; long elapsed = ctrstart_time; // Calculate the elapsed Time out[0] = start_state[0] + per_second_delta_0 * elapsed; out[1] = start_state[1] + per_second_delta_1 * elapsed; out[2] = start_state[2] + per_second_delta_2 * elapsed; }
void set_state(const int state[]) { if (state[0] >= 0 && state[0] <= 1023) { Timer3.setPwmDuty(kChan0Pin, state[0]); state_chan1 = state[0]; } if (state[1] >= 0 && state[1] <= 1023) { Timer3.setPwmDuty(kChan1Pin, state[1]); state_chan2 = state[1]; } if (state[2] >= 0 && state[2] <= 1023) { Timer3.setPwmDuty(kChan2Pin, state[2]); state_chan3 = state[2]; } }

Thread Tools  
Show Printable Version Show Printable Version
Email this Page Email this Page


Display Modes  

Posting Rules  