Proyecto final de semestre: Se desarrollo un vehículo que recibe comandos por el puerto serial y realiza las siguientes funciones según el comando sea el comando recibido: - Genera distintos tonos por un buzzer. - Controla el movimiento de un carro (con 2 motores) con comandos - Controla el movimiento de un carro (con 2 motores) con Joystick. - Lee y envía el color leido por el puerto serial al PC - Muestra los colores leídos por una pantalla FFT instalada en el vehículo.

Dependencies:   mbed UniGraphic

Committer:
CCastrop1012
Date:
Fri Sep 03 05:26:27 2021 +0000
Revision:
0:3a420fc22672
Proyecto de final de semestre, finalizado y funcional.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CCastrop1012 0:3a420fc22672 1 #include "mbed.h"
CCastrop1012 0:3a420fc22672 2 #include "scolor_TCS3200.h"
CCastrop1012 0:3a420fc22672 3
CCastrop1012 0:3a420fc22672 4
CCastrop1012 0:3a420fc22672 5 scolor_TCS3200::scolor_TCS3200(PinName s0, PinName s1, PinName s2, PinName s3, PinName s_in) :
CCastrop1012 0:3a420fc22672 6 _s0(s0), _s1(s1), _s2(s2), _s3(s3), _s_in(s_in)
CCastrop1012 0:3a420fc22672 7 {
CCastrop1012 0:3a420fc22672 8 SetMode(SCALE_100);
CCastrop1012 0:3a420fc22672 9
CCastrop1012 0:3a420fc22672 10 };
CCastrop1012 0:3a420fc22672 11
CCastrop1012 0:3a420fc22672 12
CCastrop1012 0:3a420fc22672 13 long scolor_TCS3200::ReadRed() { _s2=0; _s3=0; return pulsewidth();}
CCastrop1012 0:3a420fc22672 14 long scolor_TCS3200::ReadBlue() { _s2=0; _s3=1; return pulsewidth();}
CCastrop1012 0:3a420fc22672 15 long scolor_TCS3200::ReadClear() { _s2=1; _s3=0; return pulsewidth();}
CCastrop1012 0:3a420fc22672 16 long scolor_TCS3200::ReadGreen() { _s2=1; _s3=1; return pulsewidth();}
CCastrop1012 0:3a420fc22672 17
CCastrop1012 0:3a420fc22672 18 void scolor_TCS3200::SetMode(uint8_t mode) {
CCastrop1012 0:3a420fc22672 19 switch (mode){
CCastrop1012 0:3a420fc22672 20 case SCALE_100: _s0= 1; _s1=1; break;
CCastrop1012 0:3a420fc22672 21 case SCALE_20: _s0=1 ; _s1=0; break;
CCastrop1012 0:3a420fc22672 22 case SCALE_2: _s0=0 ; _s1=1; break;
CCastrop1012 0:3a420fc22672 23 case POWER_DOWN: _s0=0 ; _s1=0; break;
CCastrop1012 0:3a420fc22672 24 }
CCastrop1012 0:3a420fc22672 25 };
CCastrop1012 0:3a420fc22672 26
CCastrop1012 0:3a420fc22672 27 long scolor_TCS3200::pulsewidth() {
CCastrop1012 0:3a420fc22672 28 while(!_s_in);
CCastrop1012 0:3a420fc22672 29 timer.start();
CCastrop1012 0:3a420fc22672 30 while(_s_in);
CCastrop1012 0:3a420fc22672 31 timer.stop();
CCastrop1012 0:3a420fc22672 32 float pulsewidth_v = timer.read_us();
CCastrop1012 0:3a420fc22672 33 timer.reset();
CCastrop1012 0:3a420fc22672 34 return pulsewidth_v;
CCastrop1012 0:3a420fc22672 35 };
CCastrop1012 0:3a420fc22672 36
CCastrop1012 0:3a420fc22672 37