1 | /*
|
---|
2 | All IO Ports
|
---|
3 |
|
---|
4 | This example goes through all the IO ports on your robot and
|
---|
5 | reads/writes from/to them. Uncomment the different lines inside
|
---|
6 | the loop to test the different possibilities.
|
---|
7 |
|
---|
8 | The M inputs on the Control Board are multiplexed and therefore
|
---|
9 | it is not recommended to use them as outputs. The D pins on the
|
---|
10 | Control Board as well as the D pins on the Motor Board go directly
|
---|
11 | to the microcontroller and therefore can be used both as inputs
|
---|
12 | and outputs.
|
---|
13 |
|
---|
14 | Circuit:
|
---|
15 | * Arduino Robot
|
---|
16 |
|
---|
17 | created 1 May 2013
|
---|
18 | by X. Yang
|
---|
19 | modified 12 May 2013
|
---|
20 | by D. Cuartielles
|
---|
21 |
|
---|
22 | This example is in the public domain
|
---|
23 | */
|
---|
24 |
|
---|
25 | #include <ArduinoRobot.h>
|
---|
26 | #include <Wire.h>
|
---|
27 | #include <SPI.h>
|
---|
28 |
|
---|
29 | // use arrays to store the names of the pins to be read
|
---|
30 | uint8_t arr[] = { M0, M1, M2, M3, M4, M5, M6, M7 };
|
---|
31 | uint8_t arr2[] = { D0, D1, D2, D3, D4, D5 };
|
---|
32 | uint8_t arr3[] = { D7, D8, D9, D10 };
|
---|
33 |
|
---|
34 | void setup() {
|
---|
35 | // initialize the robot
|
---|
36 | Robot.begin();
|
---|
37 |
|
---|
38 | // open the serial port to send the information of what you are reading
|
---|
39 | Serial.begin(9600);
|
---|
40 | }
|
---|
41 |
|
---|
42 | void loop() {
|
---|
43 | // read all the D inputs at the Motor Board as analog
|
---|
44 | //analogReadB_Ds();
|
---|
45 |
|
---|
46 | // read all the D inputs at the Motor Board as digital
|
---|
47 | //digitalReadB_Ds();
|
---|
48 |
|
---|
49 | // read all the M inputs at the Control Board as analog
|
---|
50 | //analogReadMs();
|
---|
51 |
|
---|
52 | // read all the M inputs at the Control Board as digital
|
---|
53 | //digitalReadMs();
|
---|
54 |
|
---|
55 | // read all the D inputs at the Control Board as analog
|
---|
56 | analogReadT_Ds();
|
---|
57 |
|
---|
58 | // read all the D inputs at the Control Board as digital
|
---|
59 | //digitalReadT_Ds();
|
---|
60 |
|
---|
61 | // write all the D outputs at the Motor Board as digital
|
---|
62 | //digitalWriteB_Ds();
|
---|
63 |
|
---|
64 | // write all the D outputs at the Control Board as digital
|
---|
65 | //digitalWriteT_Ds();
|
---|
66 | delay(40);
|
---|
67 | }
|
---|
68 |
|
---|
69 | // read all M inputs on the Control Board as analog inputs
|
---|
70 | void analogReadMs() {
|
---|
71 | for (int i = 0; i < 8; i++) {
|
---|
72 | Serial.print(Robot.analogRead(arr[i]));
|
---|
73 | Serial.print(",");
|
---|
74 | }
|
---|
75 | Serial.println("");
|
---|
76 | }
|
---|
77 |
|
---|
78 | // read all M inputs on the Control Board as digital inputs
|
---|
79 | void digitalReadMs() {
|
---|
80 | for (int i = 0; i < 8; i++) {
|
---|
81 | Serial.print(Robot.digitalRead(arr[i]));
|
---|
82 | Serial.print(",");
|
---|
83 | }
|
---|
84 | Serial.println("");
|
---|
85 | }
|
---|
86 |
|
---|
87 | // read all D inputs on the Control Board as analog inputs
|
---|
88 | void analogReadT_Ds() {
|
---|
89 | for (int i = 0; i < 6; i++) {
|
---|
90 | Serial.print(Robot.analogRead(arr2[i]));
|
---|
91 | Serial.print(",");
|
---|
92 | }
|
---|
93 | Serial.println("");
|
---|
94 | }
|
---|
95 |
|
---|
96 | // read all D inputs on the Control Board as digital inputs
|
---|
97 | void digitalReadT_Ds() {
|
---|
98 | for (int i = 0; i < 6; i++) {
|
---|
99 | Serial.print(Robot.digitalRead(arr2[i]));
|
---|
100 | Serial.print(",");
|
---|
101 | }
|
---|
102 | Serial.println("");
|
---|
103 | }
|
---|
104 |
|
---|
105 | // write all D outputs on the Control Board as digital outputs
|
---|
106 | void digitalWriteT_Ds() {
|
---|
107 | // turn all the pins on
|
---|
108 | for (int i = 0; i < 6; i++) {
|
---|
109 | Robot.digitalWrite(arr2[i], HIGH);
|
---|
110 | }
|
---|
111 | delay(500);
|
---|
112 |
|
---|
113 | // turn all the pins off
|
---|
114 | for (int i = 0; i < 6; i++) {
|
---|
115 | Robot.digitalWrite(arr2[i], LOW);
|
---|
116 | }
|
---|
117 | delay(500);
|
---|
118 | }
|
---|
119 |
|
---|
120 | // write all D outputs on the Motor Board as digital outputs
|
---|
121 | void digitalWriteB_Ds() {
|
---|
122 | // turn all the pins on
|
---|
123 | for (int i = 0; i < 4; i++) {
|
---|
124 | Robot.digitalWrite(arr3[i], HIGH);
|
---|
125 | }
|
---|
126 | delay(500);
|
---|
127 |
|
---|
128 | // turn all the pins off
|
---|
129 | for (int i = 0; i < 4; i++) {
|
---|
130 | Robot.digitalWrite(arr3[i], LOW);
|
---|
131 | }
|
---|
132 | delay(500);
|
---|
133 | }
|
---|
134 |
|
---|
135 | // read all D inputs on the Motor Board as analog inputs
|
---|
136 | void analogReadB_Ds() {
|
---|
137 | for (int i = 0; i < 4; i++) {
|
---|
138 | Serial.print(Robot.analogRead(arr3[i]));
|
---|
139 | Serial.print(",");
|
---|
140 | }
|
---|
141 | Serial.println("");
|
---|
142 | }
|
---|
143 |
|
---|
144 | // read all D inputs on the Motor Board as digital inputs
|
---|
145 | void digitalReadB_Ds() {
|
---|
146 | for (int i = 0; i < 4; i++) {
|
---|
147 | Serial.print(Robot.digitalRead(arr3[i]));
|
---|
148 | Serial.print(",");
|
---|
149 | }
|
---|
150 | Serial.println("");
|
---|
151 | }
|
---|