CLASE# 10 (MECÁNICA): 6TA UNIDAD
PROGRAMACIÓN COMPLETA DEL PROYECTO: CARRO REMOTO
Hoy tuvimos dos horas de clase, en las cuales fuimos al salón de mecánica, en donde, mi grupo y yo, trabajamos en la configuración del programa completo, el cual todavía nos faltaba modificarle algunas cositas. Para terminarlo tomamos de referencia el programa que la miss Rosa Coello había subido a moodle, solo hicimos algunas modificaciones para adaptarlo a nuestro proyecto. Lo configuramos de acuerdo a los pins que estamos usando en el Arduino Uno para controlar los componentes electrónicos. Además tuvimos que modificar un poco nuestro proyecto en MIT APP INVENTOR, para que todos los componentes electrónicos se puedan manejar correctamente vía Bluetooth. Hoy los profesores dijeron que teníamos que terminar con los últimos retoques en nuestro proyecto, puesto que en la segunda hora iban a empezar con la evaluación de la sumativa del 3er parcial del segundo quinquemestre la cual consistía en tener todo lo electrónico conectado y que esté totalmente funcional. Pero la mayoría de mis compañeros no terminaron por completo su proyecto, así que los profesores dijeron que seguirían evaluando este proyecto completamente terminado la próxima semana.
PROGRAMA COMPLETO:
int
motorA1=2;
int
motorA2=3;
int velA=6;
int
motorB1=4;
int
motorB2=5;
int velB=9;
int luz1=8;
int luz2=10;
int luz3=11;
int luz4=13;
int buzzer=7;
int state = 0;
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
// Two things need to be created: the array for the notes of
the melody (in order)
// and the
duration of each (think of it like sheet music in two parts)
// BOTH ARRAYS MUST BE THE SAME SIZE!
// The melody array
int melody[] = {
NOTE_FS5, NOTE_FS5,
NOTE_D5, NOTE_B4, NOTE_B4, NOTE_E5,
NOTE_E5, NOTE_E5,
NOTE_GS5, NOTE_GS5, NOTE_A5, NOTE_B5,
NOTE_A5, NOTE_A5,
NOTE_A5, NOTE_E5, NOTE_D5, NOTE_FS5,
NOTE_FS5, NOTE_FS5,
NOTE_E5, NOTE_E5, NOTE_FS5, NOTE_E5
};
// The note duration, 8 = 8th note, 4 = quarter note, etc.
int durations[] = {
8, 8, 8, 4, 4, 4,
4, 5, 8, 8, 8, 8,
8, 8, 8, 4, 4, 4,
4, 5, 8, 8, 8, 8
};
//
determine the length of the arrays to use in the loop iteration
int
songLength = sizeof(melody)/sizeof(melody[0]);
void setup() {
Serial.begin(9600);
pinMode(motorA1,OUTPUT);
pinMode(motorA2,OUTPUT);
pinMode(motorB1,OUTPUT);
pinMode(motorB2,OUTPUT);
pinMode(velA,OUTPUT);
pinMode(velB,OUTPUT);
pinMode(buzzer,
OUTPUT);
pinMode(luz1,
OUTPUT);
pinMode(luz2,
OUTPUT);
pinMode(luz3,
OUTPUT);
pinMode(luz4,
OUTPUT);
}
void loop() {
//si el modulo DE
BLUETOOH manda dato, guardarlo en estado.STATE
if(Serial.available() > 0){
state =
Serial.read();
} // esta parte del
código es para solo 1 Carácter o Unidad.
//adelante
if (state == 'F')
{
digitalWrite(motorA1,HIGH); digitalWrite(motorB1,HIGH);
digitalWrite(motorA2,LOW); digitalWrite(motorB2,LOW);
digitalWrite(luz1,HIGH); digitalWrite(luz2,HIGH);
digitalWrite(luz3,HIGH); digitalWrite(luz4,HIGH);
// esto e para
añadir la melodia
// Iterate through
both arrays
// Notice how the
iteration variable thisNote is created in the parenthesis
// The for loop
stops when it is equal to the size of the melody array
for (int thisNote =
0; thisNote < songLength; thisNote++){
// determine the
duration of the notes that the computer understands
// divide 1000 by
the value, so the first note lasts for 1000/8 milliseconds
int duration =
1000/ durations[thisNote];
tone(buzzer,
melody[thisNote], duration);
// pause between
notes
int pause =
duration * 1.3;
delay(pause);
}
//
Serial.println('F');
//analogWrite(velA,255); analogWrite(velB,100);
//musica();
}//delay(3000);
//atrás
if (state == 'B')
{
digitalWrite(motorB1,LOW);digitalWrite(motorA1,LOW);
digitalWrite(motorB2,HIGH);digitalWrite(motorA2,HIGH);
digitalWrite(luz1,HIGH); digitalWrite(luz2,HIGH);
digitalWrite(luz3,HIGH); digitalWrite(luz4,HIGH);
// Iterate through
both arrays
// Notice how the
iteration variable thisNote is created in the parenthesis
// The for loop
stops when it is equal to the size of the melody array
for (int thisNote =
0; thisNote < songLength; thisNote++){
// determine the
duration of the notes that the computer understands
// divide 1000 by
the value, so the first note lasts for 1000/8 milliseconds
int duration =
1000/ durations[thisNote];
tone(buzzer,
melody[thisNote], duration);
// pause between notes
int pause =
duration * 1.3;
delay(pause);
}
//Serial.println('B');
//musica();
}//delay(3000);
//IZQUIERDA
if (state == 'Y'){
digitalWrite(motorA1,HIGH);
digitalWrite(motorA2,LOW);
digitalWrite(motorB1,LOW);
digitalWrite(motorB2,LOW);
// Iterate
through both arrays
// Notice how the
iteration variable thisNote is created in the parenthesis
// The for loop
stops when it is equal to the size of the melody array
for (int thisNote =
0; thisNote < songLength; thisNote++){
// determine the
duration of the notes that the computer understands
// divide 1000 by
the value, so the first note lasts for 1000/8 milliseconds
int duration =
1000/ durations[thisNote];
tone(buzzer, melody[thisNote], duration);
// pause between
notes
int pause =
duration * 1.3;
delay(pause);
}
//Serial.println('Y');
//musica();
}
//DERECHA
if (state == 'Z'){
digitalWrite(motorA1,LOW);
digitalWrite(motorA2,LOW);
digitalWrite(motorB1,HIGH);
digitalWrite(motorB2,LOW);
// Iterate
through both arrays
// Notice how the
iteration variable thisNote is created in the parenthesis
// The for loop
stops when it is equal to the size of the melody array
for (int thisNote =
0; thisNote < songLength; thisNote++){
// determine the
duration of the notes that the computer understands
// divide 1000 by
the value, so the first note lasts for 1000/8 milliseconds
int duration =
1000/ durations[thisNote];
tone(buzzer,
melody[thisNote], duration);
// pause between
notes
int pause =
duration * 1.3;
delay(pause);
}
//Serial.println('Z');
//musica();
}
//detener
if (state == 'L')
{
digitalWrite(motorA1,LOW); digitalWrite(motorB1,LOW);
digitalWrite(motorA2,LOW); digitalWrite(motorB2,LOW);
digitalWrite(buzzer,LOW); digitalWrite(luz1,LOW);
digitalWrite(luz2,LOW); digitalWrite(luz3,LOW); digitalWrite(luz4,LOW);
noTone(buzzer);
Serial.println('L');
}//delay(2000);
if(state <=
53 ){
int
valor=state-48;
valor=map(valor,0,5,0,255);
if(valor<0 o:p="">0>
valor=0;
Serial.println(valor);
analogWrite(velA,valor);
analogWrite(velB,valor);
}
if (state ==
'R')//ENCIENDE LUZ
{
digitalWrite(luz1,HIGH); digitalWrite(luz2,HIGH);
digitalWrite(luz3,HIGH); digitalWrite(luz4,HIGH);
Serial.println('R');
}
if (state == 'O')//apaga
luz
{
digitalWrite(luz1,LOW); digitalWrite(luz2,LOW);
digitalWrite(luz3,LOW); digitalWrite(luz4,LOW);
Serial.println('O');
}
if (state == 'M')// musica se prende
{
// Iterate through
both arrays
// Notice how the
iteration variable thisNote is created in the parenthesis
// The for loop
stops when it is equal to the size of the melody array
for (int thisNote =
0; thisNote < songLength; thisNote++){
// determine the
duration of the notes that the computer understands
// divide 1000 by
the value, so the first note lasts for 1000/8 milliseconds
int duration =
1000/ durations[thisNote];
tone(buzzer,
melody[thisNote], duration);
// pause between
notes
int pause =
duration * 1.3;
delay(pause);
Serial.println('M');
}
}
if (state == 'U')//
musica apaga
{
noTone(buzzer);
Serial.println('U');
}
}
//void musica()
//tone(buzzer,120,2000);
CONCLUSIÓN:
En conclusión en esta clase pudimos terminar con la programación de todos los componentes electrónicos que ya habíamos conectado días anteriores en el carro remoto. Ya que logramos darnos cuenta de algunas cosas que le faltaba a la programación de nuestro proyecto y las pusimos en ese momento. Tratamos de revisar que todo este completamente terminado en nuestro proyecto, tratando de terminar en la primera hora de clase con todo, para así poder presentarlo a tiempo, muy pulcro y con estética en la segunda hora que se iba a empezar a evaluar el aporte.
LOGROS Y DIFICULTADES:
Mi grupo y yo logramos terminar con nuestro proyecto en la primera hora. Lo que nos resultó un poco difícil a mi grupo y a mí fue añadir correctamente las cosas que nos faltaban en el programa.
QUÉ ME PREGUNTO:
Mi grupo y yo no nos preguntamos nada.
BIBLIOGRAFÍA:
- Casas Digitales (2018). ¿Cómo sería tu casa domótica? Recuperado el 17 de agosto de 2019 desde https://www.casasdigitales.com/maqueta-de-casa-domotica/
- Blanco, S. (2003). Uso didáctico de Internet. Recuperado el 17 de agosto de 2019 desde http://nogal.mentor.mec.es/~lbag0000/html/lacasadomus.htm
- Martinez, J. (2013). Maqueta de una casa Domótica (Automatizada). Recuperado el 17 de agosto de 2019 desde https://www.tutorialesje.com/2013/08/maqueta-de-una-casa-domotica.html
- CodeWeek. (2015). Guía de iniciación a App Inventor.[archivo PDF]. Recuperado de https://codeweek.eu/docs/spain/guia-iniciacion-app-inventor.pdf
- Vega, E.[we_qessG1dQ]. (2017, Junio 9). Tutorial MIT App Inventor con Arduino y Bluetooth. Varios ejemplos. [Archivo de video]. Recuperado de https://www.youtube.com/watch?v=OO7vKKuJ9a
Comentarios
Publicar un comentario