/elec/quadcopter

To get this branch, use:
bzr branch http://bzr.ed.am/elec/quadcopter

« back to all changes in this revision

Viewing changes to src/rc-interface/motors.cc

  • Committer: Tim Marston
  • Date: 2014-01-29 22:34:56 UTC
  • Revision ID: tim@ed.am-20140129223456-aees83f0x1ndvdg9
fixed some bugs in rc-interface introduced in the conversion from the motors
test program

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
void Motors::setup()
16
16
{
17
17
        // setup outputs
18
 
        for( int pin = FIRST_PIN; pin < FIRST_PIN + NUM_CHANNELS; pin++ ) {
 
18
        for( int pin = FIRST_PIN; pin < FIRST_PIN + NUM_MOTORS; pin++ ) {
19
19
                pinMode( pin, OUTPUT );
20
20
                digitalWrite( pin, LOW );
21
21
        }
35
35
 
36
36
void Motors::update()
37
37
{
38
 
        static int event = NUM_CHANNELS * 2;
 
38
        static int event = NUM_MOTORS * 2;
39
39
        unsigned long now = micros();
40
40
        static unsigned long frame_start = now - FRAME_DURATION;
41
 
        static unsigned long next_event_at;
 
41
        static unsigned long next_event_at = 0;
42
42
 
43
43
        if( now >= next_event_at )
44
44
        {
45
45
                // action event
46
 
                digitalWrite( FIRST_PIN + ( event / 2 ), ( event & 1 )? LOW : HIGH );
 
46
                if( event < NUM_MOTORS * 2 )
 
47
                        digitalWrite( FIRST_PIN + ( event / 2 ),
 
48
                                ( event & 1 )? LOW : HIGH );
47
49
 
48
50
                // move to next event
49
 
                if( ++event >= NUM_CHANNELS * 2 ) {
 
51
                if( ++event >= NUM_MOTORS * 2 ) {
50
52
                        event = 0;
51
53
                        frame_start += FRAME_DURATION;
52
54
                }