Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:b327db3eb9ce
- Parent:
- 0:1006a6a7855b
--- a/main.cpp Thu Oct 18 03:18:22 2018 +0000
+++ b/main.cpp Fri Nov 23 01:00:30 2018 +0000
@@ -3,8 +3,8 @@
Serial pc(SERIAL_TX, SERIAL_RX);
-SPI deviceM(PA_7, PA_6, PA_5);
-DigitalOut ssel (PA_4);
+SPI deviceM(PB_15, PB_14, PB_13);
+DigitalOut ssel (PB_12);
void Rx_interrupt();
#define uint8_t unsigned char
@@ -15,9 +15,130 @@
int velocidad=1000;
int segundo=1;
int verificacion=0;
+int rapido =1000;
+int vericolor=0;
+
+
+// variables y definiciones color
+DigitalOut s0(D3);
+DigitalOut s1(D4);
+DigitalOut s2(D5);
+DigitalOut s3(D6);
+
+DigitalOut led_col(D7);
+DigitalOut led1(LED1);
+DigitalIn out(D2);
+
+Timer tiempo;
+
+int valor,verificacion_color ;
+int val_color;
+int val_r,val_g,val_b;
+int ch_color;
+void analisis (void);
+
+#include "Movimiento.h"
+//////////////////////////////////////////////////////////////////////////////
+
+void analisis_color(void)
+{
+ while(verificacion_color==0)
+ {
+ valor=out.read();
+ // pc.printf("valor 1= %d \n",valor);
+ if (valor==1)
+ {
+ while(verificacion_color==0)
+ {
+ valor=out.read();
+ // pc.printf("valor 2= %d \n",valor);
+
+ if(valor==0)
+ {
+ tiempo.start();
+ }
+ while(valor==0)
+ {
+ valor=out.read();
+ // pc.printf("valor 3= %d \n",valor);
+ verificacion_color=1;
+ }
+ }
+ }
+ }
+ val_color=tiempo.read_us();
+ tiempo.reset();
+ verificacion_color=0;
+}
-#include "Movimiento.h"
+///////////////////////////////////////////////////////////////////////////////
+void datos_color(void)
+{
+ s2=0;
+ s3=0;
+ analisis();
+ //pc.printf("Rojox= %d \n",val_color);
+ val_r=val_color;
+ wait_ms(100);
+
+
+ s2=0;
+ s3=1;
+ analisis();
+ //pc.printf(" Azul= %d \n ",val_color);
+ val_b=val_color;
+ wait_ms(100);
+
+
+ s2=1;
+ s3=1;
+ analisis();
+ //pc.printf(" Verde= %d \n",val_color);
+ val_g=val_color;
+ wait_ms(100);
+
+
+ //Blanco
+ if((val_r>=600047 && val_r<=600115) &&(val_g>=100051 && val_g<=100108) && (val_b>=100044 && val_b<=100086))
+ {
+ pc.printf(" Blanco \n");
+ }
+ //rojo
+ if((val_r>=600116 && val_r<=600282) &&(val_g>=100305 && val_g<=100853) && (val_b>=100191 && val_b<=100550))
+ {
+ pc.printf(" Rojo \n");
+ }
+ //verde
+
+ if((val_r>=600283 && val_r<=600669) &&(val_g>=100143 && val_g<=100395) && (val_b>=100147 && val_b<=100409))
+ {
+ pc.printf(" Verde \n");
+ }
+
+ //Azul
+
+ if((val_r>=600570 && val_r<=601153) &&(val_g>=100199 && val_g<=100553) && (val_b>=100103 && val_b<=100122))
+ {
+ pc.printf(" Azul \n");
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void color_interrupcion (void)
+{
+
+ switch(ch_color)
+ {
+ case 1: pmenos(); break;
+ case 2: pmas(); break;
+ case 3: giros(); break;
+ default: pc.printf("Error \n");
+
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////
void sendSPI(uint8_t d1, uint8_t d2)// envio de datos al max
{
@@ -25,8 +146,7 @@
ssel=0;
deviceM.write(d1);
deviceM.write(d2);
- ssel=1;
- deviceM.lock();
+ ssel=1; deviceM.lock();
};
///////////////////////////////////////////////////////////////////////////////
void borrar() // Borrar todos los datos de la matriz
@@ -154,6 +274,8 @@
///////////////////////////////////////////////////////////////////////////////
void play () // Funcion encargada de determianr el estado de la mascara
{
+
+ pc.attach(&Rx_interrupt, Serial::RxIrq);
int a=1;
mascara=128;
//pc.printf("Posicion original 1 %d \n",posicion_original);
@@ -186,9 +308,22 @@
if(mascara==mascarax)
{
- velocidad=1000;
- }
- wait_ms(velocidad);
+ velocidad=rapido;
+
+ }
+
+ wait_ms(velocidad);
+ /*
+ for(int ch=0;ch<=1;ch++)
+ {
+ datos_color();
+ wait_ms(1);
+ if(vericolor==1)
+ {
+ color_interrupcion();
+ }
+ }
+ */
mascara=mascara/2;
@@ -202,7 +337,7 @@
int main() { // fucnion principal
pc.baud(9600);
- pc.attach(&Rx_interrupt, Serial::RxIrq);
+
sendSPI(0x0c,1);
sendSPI(0x0F,1);
wait (1);
@@ -211,15 +346,23 @@
wait (1);
sendSPI(0xB,0x7);
borrar();
+
+ led_col=1;
+ //escala de frecuencia a 20%
+ s0=1;
+ s1=0;
- int n=10;
-
+ int n;
+
+ int inicio , fin;
+
while(1){
if(verificacion==0)
{
+ /*
n=10;
while( n>6)
{
@@ -230,6 +373,33 @@
giro = 0;
wait(0.2);
mascarax=128;
+ */
+ pc.attach(0, Serial::RxIrq);
+ inicio=pc.getc();
+
+ if(inicio==60)
+ {
+
+
+
+ mascarax=128;
+ //pc.printf("Ingrese el numero de la figura \n");
+ inicio=60;
+
+ n = pc.getc();
+ //pc.printf("figura %d \n ",n);
+
+ //pc.printf("Ingrese el numero de angulo de giro \n");
+ giro = pc.getc();
+ //pc.printf("giro %d \n ",giro);
+
+ //pc.printf("Ingrese la posicion \n");
+ posicion = pc.getc();
+ //pc.printf("posicion %d \n ",posicion);
+
+ fin=pc.getc();
+ wait(0.2);
+ }
}
else
{
@@ -237,7 +407,8 @@
posicion=posicion_original;
}
-
+ if((inicio==60) && (fin==62))
+ {
switch(n)
{
case 0: a(giro); play(); break;
@@ -256,7 +427,7 @@
default: pc.printf("Error en figura \n");
}
-
+ }
}
}
////////////////////////////////////////////////////////////////////////////////////////////////