diff options
author | Cristian Maglie <c.maglie@bug.st> | 2013-05-29 18:30:36 +0200 |
---|---|---|
committer | Cristian Maglie <c.maglie@bug.st> | 2013-05-29 18:30:36 +0200 |
commit | d90fcca5839d13d57ed527d4009b78d22dafbde7 (patch) | |
tree | 768b98af21e5075846184dd3de41ae0c22e75e20 /libraries/Robot_Control/examples/learn | |
parent | 7207108255a772474b322151cb0fd113e8030afe (diff) | |
parent | ef4e8c65373f531ce6d37ff226a21fc9b358ff29 (diff) |
Merged 1.0.5
Diffstat (limited to 'libraries/Robot_Control/examples/learn')
16 files changed, 783 insertions, 0 deletions
diff --git a/libraries/Robot_Control/examples/learn/AllIOPorts/AllIOPorts.ino b/libraries/Robot_Control/examples/learn/AllIOPorts/AllIOPorts.ino new file mode 100644 index 0000000..3520214 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/AllIOPorts/AllIOPorts.ino @@ -0,0 +1,149 @@ +/* + All IO Ports + + This example goes through all the IO ports on your robot and + reads/writes from/to them. Uncomment the different lines inside + the loop to test the different possibilities. + + The TK inputs on the Control Board are multiplexed and therefore + it is not recommended to use them as outputs. The TKD pins on the + Control Board as well as the TK pins on the Motor Board go directly + to the microcontroller and therefore can be used both as inputs + and outputs. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +// use arrays to store the names of the pins to be read +uint8_t arr[] = { TK0, TK1, TK2, TK3, TK4, TK5, TK6, TK7 }; +uint8_t arr2[] = { TKD0, TKD1, TKD2, TKD3, TKD4, TKD5 }; +uint8_t arr3[] = { B_TK1, B_TK2, B_TK3, B_TK4 }; + +void setup(){ + // initialize the robot + Robot.begin(); + + // open the serial port to send the information of what you are reading + Serial.begin(9600); +} + +void loop(){ + // read all the TK inputs at the Motor Board as analog + analogReadB_TKs(); + + // read all the TK inputs at the Motor Board as digital + //digitalReadB_TKs(); + + // read all the TK inputs at the Control Board as analog + //analogReadTKs(); + + // read all the TK inputs at the Control Board as digital + //digitalReadTKs(); + + // read all the TKD inputs at the Control Board as analog + //analogReadTKDs(); + + // read all the TKD inputs at the Control Board as digital + //digitalReadTKDs(); + + // write all the TK outputs at the Motor Board as digital + //digitalWriteB_TKs(); + + // write all the TKD outputs at the Control Board as digital + //digitalWriteTKDs(); + delay(5); +} + +// read all TK inputs on the Control Board as analog inputs +void analogReadTKs() { + for(int i=0;i<8;i++) { + Serial.print(Robot.analogRead(arr[i])); + Serial.print(","); + } + Serial.println(""); +} + +// read all TK inputs on the Control Board as digital inputs +void digitalReadTKs() { + for(int i=0;i<8;i++) { + Serial.print(Robot.digitalRead(arr[i])); + Serial.print(","); + } + Serial.println(""); +} + +// read all TKD inputs on the Control Board as analog inputs +void analogReadTKDs() { + for(int i=0; i<6; i++) { + Serial.print(Robot.analogRead(arr2[i])); + Serial.print(","); + } + Serial.println(""); +} + +// read all TKD inputs on the Control Board as digital inputs +void digitalReadTKDs() { + for(int i=0; i<6; i++) { + Serial.print(Robot.digitalRead(arr2[i])); + Serial.print(","); + } + Serial.println(""); +} + +// write all TKD outputs on the Control Board as digital outputs +void digitalWriteTKDs() { + // turn all the pins on + for(int i=0; i<6; i++) { + Robot.digitalWrite(arr2[i], HIGH); + } + delay(500); + + // turn all the pins off + for(int i=0; i<6; i++){ + Robot.digitalWrite(arr2[i], LOW); + } + delay(500); +} + +// write all TK outputs on the Motor Board as digital outputs +void digitalWriteB_TKs() { + // turn all the pins on + for(int i=0; i<4; i++) { + Robot.digitalWrite(arr3[i], HIGH); + } + delay(500); + + // turn all the pins off + for(int i=0; i<4; i++) { + Robot.digitalWrite(arr3[i], LOW); + } + delay(500); +} + +// read all TK inputs on the Motor Board as analog inputs +void analogReadB_TKs() { + for(int i=0; i<4; i++) { + Serial.print(Robot.analogRead(arr3[i])); + Serial.print(","); + } + Serial.println(""); +} + +// read all TKD inputs on the Motor Board as digital inputs +void digitalReadB_TKs() { + for(int i=0; i<4; i++) { + Serial.print(Robot.digitalRead(arr3[i])); + Serial.print(","); + } + Serial.println(""); +} diff --git a/libraries/Robot_Control/examples/learn/Beep/Beep.ino b/libraries/Robot_Control/examples/learn/Beep/Beep.ino new file mode 100644 index 0000000..1a78673 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/Beep/Beep.ino @@ -0,0 +1,39 @@ +/* + Beep + + Test different pre-configured beeps on + the robot's speaker. + + Possible beeps are: + - BEEP_SIMPLE + - BEEP_DOUBLE + - BEEP_LONG + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the sound speaker + Robot.beginSpeaker(); +} +void loop() { + Robot.beep(BEEP_SIMPLE); + delay(1000); + Robot.beep(BEEP_DOUBLE); + delay(1000); + Robot.beep(BEEP_LONG); + delay(1000); +} diff --git a/libraries/Robot_Control/examples/learn/CleanEEPROM/CleanEEPROM.ino b/libraries/Robot_Control/examples/learn/CleanEEPROM/CleanEEPROM.ino new file mode 100644 index 0000000..ae14bdd --- /dev/null +++ b/libraries/Robot_Control/examples/learn/CleanEEPROM/CleanEEPROM.ino @@ -0,0 +1,41 @@ +/* + Clean EEPROM + + This example erases the user information stored on the + external EEPROM memory chip on your robot. + + BEWARE, this will erase the following information: + - your name + - your robots name given by you + - your city and country if you configured them via software + + EEPROMs shouldn't be rewritten too often, therefore the + code runs only during setup and not inside loop. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup(){ + // initialize the robot + Robot.begin(); + + // write empty strings for the different fields + Robot.userNameWrite(""); + Robot.robotNameWrite(""); + Robot.cityNameWrite(""); + Robot.countryNameWrite(""); +} + +void loop(){ + // do nothing +} diff --git a/libraries/Robot_Control/examples/learn/Compass/Compass.ino b/libraries/Robot_Control/examples/learn/Compass/Compass.ino new file mode 100644 index 0000000..4170ab7 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/Compass/Compass.ino @@ -0,0 +1,41 @@ +/* + Compass + + Try the compass both on the robot's TFT + and through the serial port. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the robot's screen + Robot.beginTFT(); + + // initialize the serial port + Serial.begin(9600); +} + +void loop() { + // read the compass + int compass = Robot.compassRead(); + + // print out the sensor's value + Serial.println(compass); + + // show the value on the robot's screen + Robot.drawCompass(compass); +} + diff --git a/libraries/Robot_Control/examples/learn/IRArray/IRArray.ino b/libraries/Robot_Control/examples/learn/IRArray/IRArray.ino new file mode 100644 index 0000000..36b4acf --- /dev/null +++ b/libraries/Robot_Control/examples/learn/IRArray/IRArray.ino @@ -0,0 +1,44 @@ +/* + IR array + + Read the analog value of the IR sensors at the + bottom of the robot. The also-called line following + sensors are a series of pairs of IR sender/receiver + used to detect how dark it is underneath the robot. + + The information coming from the sensor array is stored + into the Robot.IRarray[] and updated using the Robot.updateIR() + method. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup(){ + // initialize the robot + Robot.begin(); + + // initialize the serial port + Serial.begin(9600); +} + +void loop(){ + // store the sensor information into the array + Robot.updateIR(); + + // iterate the array and print the data to the Serial port + for(int i=0; i<5; i++){ + Serial.print(Robot.IRarray[i]); + Serial.print(" "); + } + Serial.println(""); +} diff --git a/libraries/Robot_Control/examples/learn/LCDDebugPrint/LCDDebugPrint.ino b/libraries/Robot_Control/examples/learn/LCDDebugPrint/LCDDebugPrint.ino new file mode 100644 index 0000000..0078b77 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/LCDDebugPrint/LCDDebugPrint.ino @@ -0,0 +1,37 @@ +/* + LCD Debug Print + + Use the Robot's library function debugPrint() to + quickly send a sensor reading to the robot's creen. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +int value; + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the screen + Robot.beginTFT(); +} +void loop(){ + // read a value + value = analogRead(A4); + + // send the value to the screen + Robot.debugPrint(value); + + delay(40); +} diff --git a/libraries/Robot_Control/examples/learn/LCDPrint/LCDPrint.ino b/libraries/Robot_Control/examples/learn/LCDPrint/LCDPrint.ino new file mode 100644 index 0000000..d34168c --- /dev/null +++ b/libraries/Robot_Control/examples/learn/LCDPrint/LCDPrint.ino @@ -0,0 +1,44 @@ +/* + LCD Print + + Print the reading from a sensor to the screen. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +int value; + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the robot's screen + Robot.beginLCD(); +} + +void loop() { + // read a analog port + value=Robot.analogRead(TK4); + + // write the sensor value on the screen + Robot.fill(0, 255, 0); + Robot.textSize(1); + Robot.text(value, 0, 0); + + delay(500); + + // erase the previous text on the screen + Robot.fill(255, 255, 255); + Robot.textSize(1); + Robot.text(value, 0, 0); +} diff --git a/libraries/Robot_Control/examples/learn/LCDWriteText/LCDWriteText.ino b/libraries/Robot_Control/examples/learn/LCDWriteText/LCDWriteText.ino new file mode 100644 index 0000000..e34a7d2 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/LCDWriteText/LCDWriteText.ino @@ -0,0 +1,41 @@ +/* + LCD Write Text + + Use the Robot's library function text() to + print out text to the robot's screen. Take + into account that you need to erase the + information before continuing writing. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the screen + Robot.beginTFT(); +} +void loop() { + Robot.stroke(0, 0, 0); // choose the color black + Robot.text("Hello World", 0, 0); // print the text + delay(2000); + Robot.stroke(255, 255, 255); // choose the color white + Robot.text("Hello World", 0, 0); // writing text in the same color as the BG erases the text! + + Robot.stroke(0, 0, 0); // choose the color black + Robot.text("I am a robot", 0, 0); // print the text + delay(3000); + Robot.stroke(255, 255, 255); // choose the color black + Robot.text("I am a robot", 0, 0); // print the text +} diff --git a/libraries/Robot_Control/examples/learn/LineFollowWithPause/LineFollowWithPause.ino b/libraries/Robot_Control/examples/learn/LineFollowWithPause/LineFollowWithPause.ino new file mode 100644 index 0000000..a3d3fc0 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/LineFollowWithPause/LineFollowWithPause.ino @@ -0,0 +1,49 @@ +/* + Line Following with Pause + + As the robot has two processors, one to command the motors and one to + take care of the screen and user input, it is possible to write + programs that put one part of the robot to do something and get the + other half to control it. + + This example shows how the Control Board assigns the Motor one to + follow a line, but asks it to stop every 3 seconds. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the screen + Robot.beginTFT(); + + // get some time to place the robot on the ground + delay(3000); + + // set the robot in line following mode + Robot.setMode(MODE_LINE_FOLLOW); +} + +void loop() { + // tell the robot to take a break and stop + Robot.pauseMode(true); + Robot.debugPrint('p'); + delay(3000); + + // tell the robot to move on + Robot.pauseMode(false); + Robot.debugPrint('>'); + delay(3000); +} diff --git a/libraries/Robot_Control/examples/learn/Melody/Melody.ino b/libraries/Robot_Control/examples/learn/Melody/Melody.ino new file mode 100644 index 0000000..6c049a7 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/Melody/Melody.ino @@ -0,0 +1,62 @@ +/* + Melody + + Plays a melody stored in a string. + + The notes and durations are encoded as follows: + + NOTES: + c play "C" + C play "#C" + d play "D" + D play "#D" + e play "E" + f play "F" + F play "#F" + g play "G" + G play "#G" + a play "A" + A play "#A" + b play "B" + - silence + + DURATIONS: + 1 Set as full note + 2 Set as half note + 4 Set as quarter note + 8 Set as eigth note + + SPECIAL NOTATION: + . Make the previous note 3/4 the length + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + + This code uses the Squawk sound library designed by STG. For + more information about it check: http://github.com/stg/squawk + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the sound library + Robot.beginSpeaker(); +} + +void loop() { + // array containing the melody + char aTinyMelody[] = "8eF-FFga4b.a.g.F.8beee-d2e.1-"; + + // play the melody + Robot.playMelody(aTinyMelody); +} diff --git a/libraries/Robot_Control/examples/learn/MotorTest/MotorTest.ino b/libraries/Robot_Control/examples/learn/MotorTest/MotorTest.ino new file mode 100644 index 0000000..baaaf06 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/MotorTest/MotorTest.ino @@ -0,0 +1,41 @@ +/* + Motor Test + + Just see if the robot can move and turn. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); +} + +void loop() { + Robot.motorsWrite(255,255); // move forward + delay(2000); + Robot.motorsStop(); // fast stop + delay(1000); + Robot.motorsWrite(-255,-255); // backward + delay(1000); + Robot.motorsWrite(0,0); // slow stop + delay(1000); + Robot.motorsWrite(-255,255); // turn left + delay(2000); + Robot.motorsStop(); // fast stop + delay(1000); + Robot.motorsWrite(255,-255); // turn right + delay(2000); + Robot.motorsStop(); // fast stop + delay(1000); +} diff --git a/libraries/Robot_Control/examples/learn/SpeedByPotentiometer/SpeedByPotentiometer.ino b/libraries/Robot_Control/examples/learn/SpeedByPotentiometer/SpeedByPotentiometer.ino new file mode 100644 index 0000000..e97f48d --- /dev/null +++ b/libraries/Robot_Control/examples/learn/SpeedByPotentiometer/SpeedByPotentiometer.ino @@ -0,0 +1,39 @@ +/* + Speed by Potentiometer + + Control the robot's speed using the on-board + potentiometer. The speed will be printed on + the TFT screen. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the screen + Robot.beginTFT(); +} + +void loop() { + // read the value of the potentiometer + int val=map(Robot.knobRead(), 0, 1023, -255, 255); + + // print the value to the TFT screen + Robot.debugPrint(val); + + // set the same speed on both of the robot's wheels + Robot.motorsWrite(val,val); + delay(10); +} diff --git a/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino b/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino new file mode 100644 index 0000000..543c06c --- /dev/null +++ b/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino @@ -0,0 +1,32 @@ +/* + Turn Test + + Check if the robot turns a certain amount of degrees. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); +} + +void loop(){ + Robot.turn(50); //turn 50 degrees to the right + Robot.motorsStop(); + delay(1000); + + Robot.turn(-100); //turn 100 degrees to the left + Robot.motorsStop(); + delay(1000); +} diff --git a/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino.orig b/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino.orig new file mode 100644 index 0000000..4e3624f --- /dev/null +++ b/libraries/Robot_Control/examples/learn/TurnTest/TurnTest.ino.orig @@ -0,0 +1,37 @@ +/* + Turn Test + + Check if the robot turns a certain amount of degrees. + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the robot + Robot.begin(); +} + +<<<<<<< HEAD +void loop() { + Robot.turn(50); //turn 50 degrees to the right +======= +void loop(){ + Robot.turn(50);//turn 50 degrees to the right + Robot.motorsStop(); +>>>>>>> f062f704463222e83390b4a954e211f0f7e6e66f + delay(1000); + + Robot.turn(-100);//turn 100 degrees to the left + Robot.motorsStop(); + delay(1000); +} diff --git a/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino b/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino new file mode 100644 index 0000000..5bbc0e5 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino @@ -0,0 +1,38 @@ +/* + Keyboard Test + + Check how the robot's keyboard works. This example + sends the data about the key pressed through the + serial port. + + All the buttons on the Control Board are tied up to a + single analog input pin, in this way it is possible to multiplex a + whole series of buttons on one single pin. + + It is possible to recalibrate the thresholds of the buttons using + the Robot.keyboardCalibrate() function, that takes a 5 ints long + array as parameter + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +void setup() { + // initialize the serial port + Serial.begin(9600); +} + +void loop() { + // print out the keyboard readings + Serial.println(Robot.keyboardRead()); + delay(100); +} diff --git a/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino.orig b/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino.orig new file mode 100644 index 0000000..6ee6c05 --- /dev/null +++ b/libraries/Robot_Control/examples/learn/keyboardTest/keyboardTest.ino.orig @@ -0,0 +1,49 @@ +/* + Keyboard Test + + Check how the robot's keyboard works. This example + sends the data about the key pressed through the + serial port. + + All the buttons on the Control Board are tied up to a + single analog input pin, in this way it is possible to multiplex a + whole series of buttons on one single pin. + + It is possible to recalibrate the thresholds of the buttons using + the Robot.keyboardCalibrate() function, that takes a 5 ints long + array as parameter + + Circuit: + * Arduino Robot + + created 1 May 2013 + by X. Yang + modified 12 May 2013 + by D. Cuartielles + + This example is in the public domain + */ + +#include <ArduinoRobot.h> + +<<<<<<< HEAD +// it is possible to use an array to calibrate +//int vals[] = { 0, 133, 305, 481, 724 }; + +void setup() { + // initialize the serial port + Serial.begin(9600); + + // calibrate the keyboard + //Robot.keyboardCalibrate(vals);//For the new robot only. +======= +void setup(){ + Serial.begin(9600); +>>>>>>> f062f704463222e83390b4a954e211f0f7e6e66f +} + +void loop() { + // print out the keyboard readings + Serial.println(Robot.keyboardRead()); + delay(100); +} |