4
// This software is intended to be run on a small Arduino (e.g., a Pro Mini),
5
// whose purpose is dedicated to talking to the RC system. That is to say, it
6
// listens to the PPM signal from the RC receiver and produces a compatible
7
// single for the ESCs to control the motors. It additionally talks to the main
8
// board via a trivial serial protocol. In so doing, this software relieves the
9
// main board (and software running on it) of the task of interfacing with any
12
// The 8 channels (from the RC receiver) need to be combined and fed to two
13
// interrupts on the Arduino. They need to be combined in such a way as to
14
// alternate pulses between the two interrupts (which are alternately used to
15
// read the pulses). Like this:
17
// ch1 ch3 ch5 ch7 ch2 ch4 ch6 ch8
21
// ___ | | | | | | | | ___
22
// GND ---|___|---+----+----+----+ +----+----+----+----|___|--- GND
24
// ____________________ | __ | _____________________
27
// (interrupt 0) (interrupt 1)
29
// The two resistors in the circuit are pull-down resistors (so, say 100kΩ).
30
// Without them, the Arduino is unable to read the pulse wave at all.
32
// Note that your receiver may not send pulses sequentially, in "channel order".
33
// If this turns out to be the case, you will need to arrange for the pulses to
34
// wire up the channels in an order whereby the pulses alternatively alternately
35
// between the two interrupts and adjust the channel order below.
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
59
void draw_graph( unsigned long channel_values[] )
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( "|" );
87
unsigned long channel_values[ NUM_CHANNELS ];
91
if( Receiver::read_channels( channel_values ) )
92
draw_graph( channel_values );