Está en la página 1de 14

#include <LiquidCrystal.

h>

#include <DHT.h>

#define DHTPIN A4

#define DHTTYPE DHT11

const int rs = 4, en = 5, d4=6, d5=7, d6=8, d7=9;

LiquidCrystal LCD(rs,en,d4,d5,d6,d7);

DHT dht(DHTPIN, DHTTYPE);

float arreglo[] = {4,1,2,3,5,8,6,7,9};

const int An0=A4;

int cont=0;

//float arreglo[7];

float arreglo1[7];

int j;float a;

float Temp = 0;

//MÉTODO BURBUJA

class Burbuja{

private:

int No_Elementos;

public:

Burbuja(int);

void Ordenar();

void Mostrar_LCD();
};

Burbuja::Burbuja(int _No_Elementos){

No_Elementos = _No_Elementos;

void Burbuja::Ordenar(){

int i,j; float aux;

for (i=0;i<No_Elementos;i++){

for(j=0;j<No_Elementos;j++){

if(arreglo[j] > arreglo[j+1]){

aux = arreglo[j];

arreglo[j] = arreglo [j+1];

arreglo[j+1] = aux;

void Burbuja::Mostrar_LCD(){

int i;

LCD.setCursor (6,0);

LCD.print("Ordenado");

LCD.setCursor (0,2);

for(i=1; i<(No_Elementos); i++){

LCD.print(arreglo[i]);

if ( i> (No_Elementos-1)){
break;

LCD.print('-');

Burbuja MetBurbujaArduino(9);

//METODO INSERCIÓN

class Insercion{

private:

int No_elementos;

public:

Insercion(int);

void Ordenar();

void Mostrar_LCD();

};

Insercion::Insercion(int No_elementos2){

No_elementos = No_elementos2;

void Insercion::Ordenar(){

int i,pos; float aux;

for(i = 0; i<No_elementos;i++){

pos = i;

aux = arreglo[i];
while((pos>0) && (arreglo[pos-1]) > aux){

arreglo[pos] = arreglo[pos-1];

pos--;

arreglo[pos] = aux;

void Insercion::Mostrar_LCD(){

int i;

LCD.setCursor (6,0);

LCD.print("Ordenado");

LCD.setCursor (1,2);

for (i=0;i<(No_elementos+1); i++){;

LCD.print(arreglo[i]);

if ( i> (No_elementos-1)){

break;

LCD.print('-');

Insercion MetInsercion(8);

//METODO SELECCION
class Seleccion{

private:

int No_Elementos;

public:

Seleccion(int);

void Ordenar();

void Mostrar_LCD();

};

Seleccion::Seleccion(int No_Elementos2){

No_Elementos = No_Elementos2;

void Seleccion::Ordenar(){

int i,j; float aux; int vmin;

for(int i=0;i<No_Elementos;i++ ){

vmin = i;

for(j=i+1;j< No_Elementos;j++){

if(arreglo[j] < arreglo[vmin]) vmin=j;

if(i!=vmin){

aux= arreglo[i];

arreglo[i]=arreglo[vmin];

arreglo[vmin]= aux;

}
void Seleccion::Mostrar_LCD(){

int i;

LCD.setCursor (6,0);

LCD.print("Ordenado");

LCD.setCursor (1,2);

for (i=0;i< No_Elementos+1; i++){

LCD.print(arreglo[i]);

if(i>No_Elementos-1){

break;

LCD.print('-');

Seleccion MetSeleccion(8);

//VOLTIMETRO

class Voltimetro {

private:

float canal;

public:

Voltimetro(float);

float lectura();

float map2(float,float,float,float,float);
};

Voltimetro::Voltimetro(float _canal){

canal = _canal;

float Voltimetro::lectura(){

return analogRead(canal);

float Voltimetro::map2(float x, float in_min, float in_max, float out_min, float out_max){

return (x-in_min)*(out_max-out_min)/(in_max-in_min)+(out_min);

Voltimetro Lectura_ADC(An0);

//////////////////////////////////////////////////////////////

void Pasar(){

for(j=0;j<8;j++){

a=arreglo[j];

arreglo1[j]=a;

void Espera(int pin){

while(1){
if(digitalRead(pin)==LOW){

break;

void MostrarArreglo(){

for(int i=0;i<8;i++){

LCD.print(arreglo1[i]);

if(i<8-1){

LCD.print('-');

delay(2000);

LCD.clear();

void MostrarDes(){

LCD.print("Arreglo");

LCD.setCursor(0,1);

LCD.print("Desordenado");

delay(1000);

LCD.clear();

////////////////////////////////////////////////////

void setup() {

pinMode(14,INPUT);

LCD.begin(20,4);
LCD.setCursor (0,1);

LCD.print("Metodos de");

LCD.setCursor (8,2);

LCD.print("ordenamiento");

delay(2000);

LCD.clear();

void loop() {

float h = dht.readHumidity();

float t = dht.readTemperature();

LCD.setCursor (0,0);

LCD.print("Burbuja");

LCD.setCursor (0,1);

LCD.print("Insercion");

LCD.setCursor (0,2);

LCD.print("Seleccion");

LCD.setCursor (0,3);

LCD.print("Datos");

if (digitalRead(A0)== HIGH){

LCD.clear();

LCD.setCursor (4,1);

LCD.print("Ordenamiento");

LCD.setCursor (6,2);

LCD.print("Burbuja");
delay(2000);

LCD.clear();

MostrarDes();

MostrarArreglo();

MetBurbujaArduino.Ordenar();

MetBurbujaArduino.Mostrar_LCD();

delay(7000);

LCD.clear();

if (digitalRead(A1)==HIGH){

LCD.clear();

LCD.setCursor (4,1);

LCD.print("Ordenamiento");

LCD.setCursor (5,2);

LCD.print("Insercion");

delay(1000);

LCD.clear();

MostrarDes();

MostrarArreglo();

MetInsercion.Ordenar();

MetInsercion.Mostrar_LCD();

delay(2000);

LCD.clear();

if (digitalRead(A2)==HIGH){

LCD.clear();
LCD.setCursor (4,1);

LCD.print("Ordenamiento");

LCD.setCursor (5,2);

LCD.print("Seleccion");

delay(2000);

LCD.clear();

MostrarDes();

MostrarArreglo();

MetSeleccion.Ordenar();

MetSeleccion.Mostrar_LCD();

delay(2000);

LCD.clear();

if (digitalRead(A3)==HIGH){

Espera(A3);

cont++;

Temp = Lectura_ADC.lectura();

Temp = Lectura_ADC.map2(Temp,0,1023,0,5);

LCD.print(Temp);

if(cont==1){

LCD.clear();

arreglo[0]=Temp;

LCD.setCursor(0,1);

LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();
}

else if(cont==2){

LCD.clear();

arreglo[1]=Temp;

LCD.setCursor(0,1);

LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();

else if(cont==3){

LCD.clear();

arreglo[2]=Temp;

LCD.setCursor(0,1);

LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();

else if(cont==4){

LCD.clear();

arreglo[3]=Temp;

LCD.setCursor(0,1);

LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();

else if(cont==5){

LCD.clear();

arreglo[4]=Temp;

LCD.setCursor(0,1);
LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();

else if(cont==6){

LCD.clear();

arreglo[5]=Temp;

LCD.setCursor(0,1);

LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();

else if(cont==7){

LCD.clear();

arreglo[6]=Temp;

LCD.setCursor(0,1);

LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();

else if(cont==8){

LCD.clear();

arreglo[7]=Temp;

LCD.setCursor(0,1);

LCD.print("Dato "); LCD.print(cont); LCD.print(" Guardado");

delay (1000);

LCD.clear();

Pasar();
delay(500);

Temp = Lectura_ADC.lectura();

Temp = Lectura_ADC.map2(Temp,0,1023,0,5);

También podría gustarte