/*
* XBEE SMS SENDER
* ---------------
*Con este codigo podras controlar los pines
3, 4, 5, 6, 7, 8, 12, 13 y tambien 9, 10, 11 como pwm
de otro arduino usando la shield Xbee de http://www.libelium.com/
*En el arduino que recibe deberas cargar el codigo SimpleMessageSystem de http://tof.danslchamp.org
--------------------------------------------
*This code will control the Digital pins
3, 4, 5, 6, 7, 8, 12, 13 and the 9, 10, 11 as pwm
of other arduino using xbee shield from http://www.libelium.com/
*In the receiving arduino you should load the code SimpleMessageSystem from http://tof.danslchamp.org
---------------------------------
---------colorsound 07-----------
---------------------------------
*/
int mandaD[] = {3, 4, 5, 6, 7, 8, 12, 13}; //array de los pines digitales a los que queremos mandar
int manda[] = { 9, 10, 11}; // array de los pines de pwm que queremos mandar
int ultimo[8] = {LOW}; // el ultimo valor de los pines
int ahora[8] = {LOW}; // el valor de los pines ahora
int lastAnalogValue[3];
// array del valor de los pines analogicos 0,1,2
//para comparar en el siguiente loop
char* pinValue[] = {"3", "4", "5", "6", "7", "8", "12", "13"};
// char para aņadir el numero de pin en el mensaje
void setup(){
for (int i=0; i<8; i++){
pinMode(mandaD[i], INPUT); //los pines digitales se declaran como entrada
}
Serial.begin(19200);
}
void loop(){
for (int j=0; j<8; j++){
ahora[j] = digitalRead(mandaD[j]);
if(ahora[j] != ultimo[j]){
if(ahora[j] == HIGH){
//Serial.print("w d" pinValue[j] 1 \r ");
Serial.print("w d ");
Serial.print(pinValue[j]);
Serial.print(" 1 \r");
}else{
//Serial.print("w d pinValue[j] 0 \r ");
Serial.print("w d ");
Serial.print(pinValue[j]);
Serial.print(" 0 \r");
}
ultimo[j] = ahora[j];
}
//recoge el valor del los pines analogicos (0,1,2) y lo manda como pwm
for (int a=0; a<=2; a++){
if (((analogRead(a)/4) >= lastAnalogValue[a]+6) || ((analogRead(a)/4) <= lastAnalogValue[a]-6)) {
if ((analogRead(a)/4) != lastAnalogValue[a]){
Serial.print("w a ");
Serial.print(manda[a]);
Serial.print(" ");
Serial.print((analogRead(a)/4)); // a/4 >> convierte el valor de 0..1023 a 0..255 para pwm
Serial.print(" \r");
}
}
lastAnalogValue[a] = (analogRead(a)/4); // guarda el ultimo valor
}
delay(100);
}
}