/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-22 23:55:10 UTC
  • Revision ID: tim@ed.am-20140122235510-dcru5aea679wyk7c
added python GTK test program that reads and displays the serial data from the
RC interface software

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_MOTORS; pin++ ) {
 
18
        for( int pin = FIRST_PIN; pin < FIRST_PIN + NUM_CHANNELS; 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_MOTORS * 2;
 
38
        static int event = NUM_CHANNELS * 2;
39
39
        unsigned long now = micros();
40
40
        static unsigned long frame_start = now - FRAME_DURATION;
41
 
        static unsigned long next_event_at = 0;
 
41
        static unsigned long next_event_at;
42
42
 
43
43
        if( now >= next_event_at )
44
44
        {
45
45
                // action event
46
 
                if( event < NUM_MOTORS * 2 )
47
 
                        digitalWrite( FIRST_PIN + ( event / 2 ),
48
 
                                ( event & 1 )? LOW : HIGH );
 
46
                digitalWrite( FIRST_PIN + ( event / 2 ), ( event & 1 )? LOW : HIGH );
49
47
 
50
48
                // move to next event
51
 
                if( ++event >= NUM_MOTORS * 2 ) {
 
49
                if( ++event >= NUM_CHANNELS * 2 ) {
52
50
                        event = 0;
53
51
                        frame_start += FRAME_DURATION;
54
52
                }