1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-23 19:21:59 +03:00

SPI library to the new format and moved Robot_Motor and Robot_Control libraries

This commit is contained in:
Fede85
2013-07-03 22:00:02 +02:00
parent 87d3b4f56b
commit 2371e2ce0d
98 changed files with 14 additions and 216 deletions

View File

@ -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("");
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -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("");
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}