Paso 5: El código
#include < NewPing.h >
#define TRIGGER_PIN 12 / / pin Arduino atado para activar el pin en el sensor de ultrasonidos.
#define ECHO_PIN 11 / / atado de Arduino pin a pin en el sensor ultrasónico del eco.
#define MAX_DISTANCE 200 / / distancia máxima queremos ping para (en centímetros). Distancia máxima del sensor está valorada en 400-500cm.
Sonar de NewPing (TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int protonoumero;
int deyteronoumero;
int tritonoumero;
int tetartonoumero;
int tetrapsifios = 0;
void setup() {}
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(13,OUTPUT);
}
void loop() {}
unsigned int nos = sonar.ping();
tetrapsifios =(uS / US_ROUNDTRIP_CM);
Si (tetrapsifios < = 9) {}
digitalWrite(13,1);
Delay(10);
Si (tetrapsifios < = 5) {}
Delay(20);
}
tetartonoumero = tetrapsifios;
tritonoumero = 0;
deyteronoumero = 0;
protonoumero = 0;
}
Si (tetrapsifios > 9 & & tetrapsifios < = 99) {}
tritonoumero = tetrapsifios/10;
tetartonoumero=tetrapsifios-(tritonoumero*10);
deyteronoumero = 0; protonoumero = 0;
}
Si (tetrapsifios > 99 & & tetrapsifios < = 999) {}
deyteronoumero = tetrapsifios/100;
tritonoumero=((tetrapsifios-(deyteronoumero*100))/10);
tetartonoumero=(tetrapsifios-(deyteronoumero*100))-(tritonoumero*10);
protonoumero = 0; }
Si (tetrapsifios > 999) {tetartonoumero = 0; tritonoumero = 0; deyteronoumero = 0; protonoumero = 0;} para (int t = 0; t < 10; t) {}
digitalWrite(13,0);
digitalWrite(8,1);
digitalWrite(7,0);
digitalWrite(6,0);
digitalWrite(5,0);
Anama(tetartonoumero);
Delay(5);
digitalWrite(8,0);
digitalWrite(7,1);
digitalWrite(6,0);
digitalWrite(5,0);
Anama(tritonoumero);
Delay(5);
digitalWrite(8,0);
digitalWrite(7,0);
digitalWrite(6,1);
digitalWrite(5,0);
Anama(deyteronoumero);
Delay(5);
digitalWrite(8,0);
digitalWrite(7,0);
digitalWrite(6,0);
digitalWrite(5,1);
Anama(protonoumero);
Delay(5);
t = t + 1;
}
}
void anama (int noumero) {}
interruptor (noumero) {}
caso 0:
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,0);
rotura;
caso 1:
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,0);
rotura;
caso 2:
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(9,0);
rotura;
caso 3:
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,0);
digitalWrite(9,0);
rotura;
caso 4:
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(9,0);
rotura;
caso 5:
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,1);
digitalWrite(9,0);
rotura;
caso 6:
digitalWrite(2,0);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(9,0);
rotura;
caso 7:
digitalWrite(2,1);
digitalWrite(3,1);
digitalWrite(4,1);
digitalWrite(9,0);
rotura;
caso 8:
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,1);
rotura;
caso 9:
digitalWrite(2,1);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(9,1);
rotura;
}
}