/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: dan
  • Date: 2016-04-10 13:36:22 UTC
  • Revision ID: dan-20160410133622-eagrslv007bj3loz
Updated Megashield project after long time

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
67
75
void setup()
68
76
{
 
77
        // init subsystems
69
78
        Receiver::setup();
70
79
        Motors::setup();
71
80
        Comms::setup();
75
84
        digitalWrite( LED_PIN, LOW );
76
85
}
77
86
 
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 ];
89
90
        int channel_values[ NUM_CHANNELS ];
90
91
 
 
92
        // reset the motor values
 
93
        for( int a = 0; a < NUM_MOTORS; a++ )
 
94
                motor_values[ a ] = 0;
 
95
 
91
96
        while( true )
92
97
        {
93
98
                // have we read a whole set of channel values?
94
99
                if( Receiver::read_channels( channel_values ) )
95
100
                {
96
 
                        // update motors
97
 
                        Motors::update();
98
 
 
99
101
                        // yes, flash led!
100
102
                        flash_led();
101
103
 
102
104
                        // send channel values to main board
103
105
                        Comms::write_channels( channel_values );
104
 
 
 
106
                }
 
107
 
 
108
                // update motors
 
109
                Motors::update();
 
110
 
 
111
                // read channel values from main board
 
112
                if( Comms::read_channels( motor_values ) )
 
113
                {
105
114
                        // set motor speeds
106
 
                        Motors::set_values( channel_values );
 
115
                        Motors::set_values( motor_values );
107
116
                }
108
117
 
109
118
                // update motors