2013-05-15 10:47:17 +02:00
|
|
|
/*
|
|
|
|
All IO Ports
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-15 10:47:17 +02:00
|
|
|
This example goes through all the IO ports on your robot and
|
2013-10-21 09:58:40 +02:00
|
|
|
reads/writes from/to them. Uncomment the different lines inside
|
2013-05-15 10:47:17 +02:00
|
|
|
the loop to test the different possibilities.
|
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
The M inputs on the Control Board are multiplexed and therefore
|
2013-08-21 23:04:42 +02:00
|
|
|
it is not recommended to use them as outputs. The D pins on the
|
|
|
|
Control Board as well as the D pins on the Motor Board go directly
|
2013-10-21 09:58:40 +02:00
|
|
|
to the microcontroller and therefore can be used both as inputs
|
2013-05-15 10:47:17 +02:00
|
|
|
and outputs.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-15 10:47:17 +02:00
|
|
|
Circuit:
|
|
|
|
* Arduino Robot
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-15 10:47:17 +02:00
|
|
|
created 1 May 2013
|
|
|
|
by X. Yang
|
|
|
|
modified 12 May 2013
|
|
|
|
by D. Cuartielles
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2013-05-15 10:47:17 +02:00
|
|
|
This example is in the public domain
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ArduinoRobot.h>
|
2014-02-12 02:02:20 +01:00
|
|
|
#include <Wire.h>
|
|
|
|
#include <SPI.h>
|
2013-05-15 10:47:17 +02:00
|
|
|
|
|
|
|
// use arrays to store the names of the pins to be read
|
2013-08-21 23:04:42 +02:00
|
|
|
uint8_t arr[] = { M0, M1, M2, M3, M4, M5, M6, M7 };
|
|
|
|
uint8_t arr2[] = { D0, D1, D2, D3, D4, D5 };
|
|
|
|
uint8_t arr3[] = { D7, D8, D9, D10 };
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
void setup() {
|
2013-05-15 10:47:17 +02:00
|
|
|
// initialize the robot
|
|
|
|
Robot.begin();
|
|
|
|
|
|
|
|
// open the serial port to send the information of what you are reading
|
|
|
|
Serial.begin(9600);
|
|
|
|
}
|
|
|
|
|
2013-10-21 09:58:40 +02:00
|
|
|
void loop() {
|
|
|
|
// read all the D inputs at the Motor Board as analog
|
2013-08-21 23:04:42 +02:00
|
|
|
//analogReadB_Ds();
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all the D inputs at the Motor Board as digital
|
|
|
|
//digitalReadB_Ds();
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all the M inputs at the Control Board as analog
|
|
|
|
//analogReadMs();
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all the M inputs at the Control Board as digital
|
|
|
|
//digitalReadMs();
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all the D inputs at the Control Board as analog
|
|
|
|
analogReadT_Ds();
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all the D inputs at the Control Board as digital
|
|
|
|
//digitalReadT_Ds();
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// write all the D outputs at the Motor Board as digital
|
|
|
|
//digitalWriteB_Ds();
|
2013-05-15 10:47:17 +02:00
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// write all the D outputs at the Control Board as digital
|
|
|
|
//digitalWriteT_Ds();
|
2013-10-21 09:58:40 +02:00
|
|
|
delay(40);
|
2013-05-15 10:47:17 +02:00
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all M inputs on the Control Board as analog inputs
|
|
|
|
void analogReadMs() {
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Serial.print(Robot.analogRead(arr[i]));
|
|
|
|
Serial.print(",");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all M inputs on the Control Board as digital inputs
|
|
|
|
void digitalReadMs() {
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 8; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Serial.print(Robot.digitalRead(arr[i]));
|
|
|
|
Serial.print(",");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all D inputs on the Control Board as analog inputs
|
|
|
|
void analogReadT_Ds() {
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Serial.print(Robot.analogRead(arr2[i]));
|
|
|
|
Serial.print(",");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all D inputs on the Control Board as digital inputs
|
|
|
|
void digitalReadT_Ds() {
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Serial.print(Robot.digitalRead(arr2[i]));
|
|
|
|
Serial.print(",");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// write all D outputs on the Control Board as digital outputs
|
|
|
|
void digitalWriteT_Ds() {
|
2013-05-15 10:47:17 +02:00
|
|
|
// turn all the pins on
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Robot.digitalWrite(arr2[i], HIGH);
|
|
|
|
}
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
// turn all the pins off
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Robot.digitalWrite(arr2[i], LOW);
|
|
|
|
}
|
|
|
|
delay(500);
|
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// write all D outputs on the Motor Board as digital outputs
|
|
|
|
void digitalWriteB_Ds() {
|
2013-05-15 10:47:17 +02:00
|
|
|
// turn all the pins on
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Robot.digitalWrite(arr3[i], HIGH);
|
|
|
|
}
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
// turn all the pins off
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Robot.digitalWrite(arr3[i], LOW);
|
|
|
|
}
|
|
|
|
delay(500);
|
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all D inputs on the Motor Board as analog inputs
|
|
|
|
void analogReadB_Ds() {
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Serial.print(Robot.analogRead(arr3[i]));
|
|
|
|
Serial.print(",");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
}
|
|
|
|
|
2013-08-21 23:04:42 +02:00
|
|
|
// read all D inputs on the Motor Board as digital inputs
|
|
|
|
void digitalReadB_Ds() {
|
2013-10-21 09:58:40 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2013-05-15 10:47:17 +02:00
|
|
|
Serial.print(Robot.digitalRead(arr3[i]));
|
|
|
|
Serial.print(",");
|
|
|
|
}
|
|
|
|
Serial.println("");
|
|
|
|
}
|