User Manual

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <pololu/orangutan.h>
/*
* serial1: for the Orangutan controllers and 3pi robot.
*
* This example listens for bytes on PD0/RXD. Whenever it receives a byte, it
* performs a custom action. Whenever the user presses the middle button, it
* transmits a greeting on PD1/TXD.
*
* The Baby Orangutan does not have a green LED, LCD, or pushbuttons so
* that part of the code will not work.
*
* To make this example compile for the Orangutan SVP, you
* must add a first argument of UART0 to all the serial_*
* function calls.
*
* http://www.pololu.com/docs/0J20
* http://www.pololu.com
* http://forum.pololu.com
*/
// receive_buffer: A ring buffer that we will use to receive bytes on PD0/RXD.
// The OrangutanSerial library will put received bytes in to
// the buffer starting at the beginning (receiveBuffer[0]).
// After the buffer has been filled, the library will automatically
// start over at the beginning.
char receive_buffer[32];
// receive_buffer_position: This variable will keep track of which bytes in the receive buffer
// we have already processed. It is the offset (0-31) of the next byte
// in the buffer to process.
unsigned char receive_buffer_position = 0;
// send_buffer: A buffer for sending bytes on PD1/TXD.
char send_buffer[32];
// wait_for_sending_to_finish: Waits for the bytes in the send buffer to
// finish transmitting on PD1/TXD. We must call this before modifying
// send_buffer or trying to send more bytes, because otherwise we could
// corrupt an existing transmission.
void wait_for_sending_to_finish()
{
while(!serial_send_buffer_empty());
}
// process_received_byte: Responds to a byte that has been received on
// PD0/RXD. If you are writing your own serial program, you can
// replace all the code in this function with your own custom behaviors.
void process_received_byte(char byte)
{
switch(byte)
{
// If the character 'G' is received, turn on the green LED.
case 'G':
green_led(1);
break;
// If the character 'g' is received, turn off the green LED.
case 'g':
green_led(0);
break;
?
Pololu AVR C/C++ Library User’s Guide © 2001–2019 Pololu Corporation
3. Functional Overview and Example programs Page 32 of 56