/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/main.ino

  • Committer: Tim Marston
  • Date: 2014-02-05 20:30:43 UTC
  • Revision ID: tim@ed.am-20140205203043-mkxrtvjww6cte95n
updated rc-interface comments

Show diffs side-by-side

added added

removed removed

64
64
#include "comms.h"
65
65
 
66
66
 
67
 
void flash_led()
68
 
{
69
 
        static bool on = false;
70
 
        on = !on;
71
 
        digitalWrite( LED_PIN, on? HIGH : LOW );
72
 
}
73
 
 
74
 
 
75
67
void setup()
76
68
{
77
 
        // init subsystems
78
69
        Receiver::setup();
79
70
        Motors::setup();
80
71
        Comms::setup();
84
75
        digitalWrite( LED_PIN, LOW );
85
76
}
86
77
 
 
78
 
 
79
void flash_led()
 
80
{
 
81
        static bool on = false;
 
82
        on = !on;
 
83
        digitalWrite( LED_PIN, on? HIGH : LOW );
 
84
}
 
85
 
 
86
 
87
87
void loop()
88
88
{
89
 
        int motor_values[ NUM_MOTORS ];
90
89
        int channel_values[ NUM_CHANNELS ];
91
90
 
92
 
        // reset the motor values
93
 
        for( int a = 0; a < NUM_MOTORS; a++ )
94
 
                motor_values[ a ] = 0;
95
 
 
96
91
        while( true )
97
92
        {
98
93
                // have we read a whole set of channel values?
99
94
                if( Receiver::read_channels( channel_values ) )
100
95
                {
 
96
                        // update motors
 
97
                        Motors::update();
 
98
 
101
99
                        // yes, flash led!
102
100
                        flash_led();
103
101
 
104
102
                        // send channel values to main board
105
103
                        Comms::write_channels( channel_values );
106
 
                }
107
 
 
108
 
                // update motors
109
 
                Motors::update();
110
 
 
111
 
                // read channel values from main board
112
 
                if( Comms::read_channels( motor_values ) )
113
 
                {
 
104
 
114
105
                        // set motor speeds
115
 
                        Motors::set_values( motor_values );
 
106
                        Motors::set_values( channel_values );
116
107
                }
117
108
 
118
109
                // update motors