12
static int channels_[ NUM_MOTORS ];
18
for( int pin = FIRST_PIN; pin < FIRST_PIN + NUM_CHANNELS; pin++ ) {
19
pinMode( pin, OUTPUT );
20
digitalWrite( pin, LOW );
23
// reset channel values
24
for( int a = 0; a < NUM_MOTORS; a++ )
29
void Motors::set_values( int channel_values[] )
31
for( int a = 0; a < NUM_MOTORS; a++ )
32
channels_[ a ] = channel_values[ a ];
38
static int event = NUM_CHANNELS * 2;
39
unsigned long now = micros();
40
static unsigned long frame_start = now - FRAME_DURATION;
41
static unsigned long next_event_at;
43
if( now >= next_event_at )
46
digitalWrite( FIRST_PIN + ( event / 2 ), ( event & 1 )? LOW : HIGH );
49
if( ++event >= NUM_CHANNELS * 2 ) {
51
frame_start += FRAME_DURATION;
54
// calculate the time that the next event will occur
55
next_event_at = frame_start + ( event / 2 ) * CHANNEL_INTERVAL;
57
next_event_at += MIN_PULSE_WIDTH + channels_[ event / 2 ] *
58
( MAX_PULSE_WIDTH - MIN_PULSE_WIDTH ) / MAX_CHANNEL_VALUE;
60
// Serial.print( event / 2 );
61
// Serial.print( ( event & 1 )? 'v' : '^' );
62
// Serial.print( " " );
63
// Serial.println( next_event_at );
66
// unsigned long width = MIN_PULSE_WIDTH +
67
// (unsigned long)channels_[ event / 2 ] *
68
// ( MAX_PULSE_WIDTH - MIN_PULSE_WIDTH ) / MAX_CHANNEL_VALUE;
69
// Serial.print( channels_[ event / 2 ] );
70
// Serial.print( " " );
71
// Serial.println( width );