35
32
// Note that your receiver may not send pulses sequentially, in "channel order".
36
33
// If this turns out to be the case, you will need to arrange for the pulses to
37
// wire up the channels in an order whereby the pulses arrive alternately
38
// between the two interrupts and adjust the channel order in config.h.
43
// The four motor control outputs should be fed directly to the ESCs.
48
// ___________________ | __ | __ | __ | _____
50
// pin 4 o o o o pin 7
55
// The serial interface (pins 0 and 1) talk a very simple protocol. When a
56
// complete set of 8 channel values have been read, it writes 0xffff followed by
57
// the 8, 16-bit unsigned channel values. It expects to recieve 0xffff,
58
// followed by 4, 16-bit unsigned channel values. All channel values are in the
59
// range specified in config.h.
34
// wire up the channels in an order whereby the pulses alternatively alternately
35
// between the two interrupts and adjust the channel order below.
61
38
#include "config.h"
62
39
#include "receiver.h"
42
// the width of the display of a single channel (in chars)
45
// the channel's expected range for use in drawing (should be similar to
46
// {MAX,MIN}_PULSE_WIDTH values)
47
#define GRAPH_MIN 1000
48
#define GRAPH_MAX 2000
74
pinMode( LED_PIN, OUTPUT );
75
digitalWrite( LED_PIN, LOW );
59
void draw_graph( unsigned long channel_values[] )
81
static bool on = false;
83
digitalWrite( LED_PIN, on? HIGH : LOW );
62
static char graph[ GRAPH_SIZE + 2 ];
63
static char inited_graph = false;
65
for( int a = 1; a < GRAPH_SIZE + 1; a++ )
68
graph[ GRAPH_SIZE + 1 ] = 0;
73
for( int a = 0; a < NUM_CHANNELS; a++ ) {
74
unsigned long value = max( 0,
75
min( channel_values[ a ], GRAPH_MAX ) - GRAPH_MIN );
76
int pos = ( GRAPH_SIZE ) * value / ( GRAPH_MAX - GRAPH_MIN );
77
graph[ pos + 1 ] = '^';
78
Serial.print( graph );
79
graph[ pos + 1 ] = '_';
81
Serial.println( "|" );
89
int channel_values[ NUM_CHANNELS ];
87
unsigned long channel_values[ NUM_CHANNELS ];
93
// have we read a whole set of channel values?
94
91
if( Receiver::read_channels( channel_values ) )
102
// send channel values to main board
103
Comms::write_channels( channel_values );
106
Motors::set_values( channel_values );
92
draw_graph( channel_values );