Por el momento, el programa es un simple reloj con alarma. Pones la hora de la alarma y empieza una canción cuando coinciden alarma y reloj. Aquí teneis unas capturas y el código para mobile!
CÓDIGO MOBILE PROCESSING:
import processing.sound.*;
Sound cancioncilla = new Sound("alarma.wav");
PFont pFont; //fuente
PButton button; //botón
boolean control_alarma; //control de si está activada o no la alarma
//variables donde se guarda la alarma
String [] alarma = new String[2]; //donde guardaremos alarma
String [] alarm = new String[2]; //string editable
void guarda_alarma()
{
alarm[0]=""; //horas
alarm[1]=""; //minutos
int num=2;
alarma[0]=textInput("introduce hora", alarm[0], num);
alarma[1]=textInput("introduce minutos", alarm[1], num);
}
void setup()
{
background(204);
button = new PButton("Alarma");
// coge y mostrará la fuente por defecto del sistema
button.calculateBounds(0,0,width,height);
button.setBounds((width-button.width)/2,height-button.height,button.width,button.height);
button.initialize();
pFont = loadFont();
textFont(pFont);
//alinea el texto en el centro
textAlign(CENTER);
}
void draw() {
background(204);
//inicializamos variable de diferencia horaria respecto la máquina
int diferencia =1;
int s = second(); // Values from 0 - 59
int m = minute(); // Values from 0 - 59
int h = diferencia + hour(); // Values from 0 - 23
//ellipse(width/2,height/2-10, width-30,height-70); //esfera del reloj
String horas = str(h);
String minutos = str(m);
//muestra hora actual por pantalla
fill(0);
textAlign(LEFT);
text("EL RELOJ-ALARMA DEFINITIVO", 30,40);
text("hora actual--> "+horas+":"+minutos, 80,80);
button.draw();
if (!control_alarma)
{
fill(180,0,0);
textAlign(LEFT);
text("alarma NO activada", 80, 100);
}
if (control_alarma)
{
fill(0,180,0);
textAlign(LEFT);
text("sonará a las "+alarma[0]+":"+alarma[1], 80, 100);
}
// compara hora actual con la de la alarma
if(horas.equals(alarma[0])&& minutos.equals(alarma[1]) == true)
{
cancioncilla.volume(100);
cancioncilla.play();
//conectar con cochecito
fill(0,0,180);
textAlign(LEFT);
text("ahora suena", 80, 120);
}
}
void keyPressed()
{
//// let the button handle any keypresses
button.keyPressed();
}
void keyReleased()
{
//// let the button handle any keyreleases. this is
//// important as PButton sends its event on release!
button.keyReleased();
}
void libraryEvent(Object library, int event, Object data) {
if (library == button) {
//// if the button sent a library event, it was pressed!
guarda_alarma();
control_alarma = !control_alarma;
}
if (library == cancioncilla) {
text("suenas", 80,140);
}
}
Debemos añadir la parte de la transmisión bluetooth del programa y solucionar la excepción de java cuando acaba el archivo de audio. Estamos en ello!!!
Sound cancioncilla = new Sound("alarma.wav");
PFont pFont; //fuente
PButton button; //botón
boolean control_alarma; //control de si está activada o no la alarma
//variables donde se guarda la alarma
String [] alarma = new String[2]; //donde guardaremos alarma
String [] alarm = new String[2]; //string editable
void guarda_alarma()
{
alarm[0]=""; //horas
alarm[1]=""; //minutos
int num=2;
alarma[0]=textInput("introduce hora", alarm[0], num);
alarma[1]=textInput("introduce minutos", alarm[1], num);
}
void setup()
{
background(204);
button = new PButton("Alarma");
// coge y mostrará la fuente por defecto del sistema
button.calculateBounds(0,0,width,height);
button.setBounds((width-button.width)/2,height-button.height,button.width,button.height);
button.initialize();
pFont = loadFont();
textFont(pFont);
//alinea el texto en el centro
textAlign(CENTER);
}
void draw() {
background(204);
//inicializamos variable de diferencia horaria respecto la máquina
int diferencia =1;
int s = second(); // Values from 0 - 59
int m = minute(); // Values from 0 - 59
int h = diferencia + hour(); // Values from 0 - 23
//ellipse(width/2,height/2-10, width-30,height-70); //esfera del reloj
String horas = str(h);
String minutos = str(m);
//muestra hora actual por pantalla
fill(0);
textAlign(LEFT);
text("EL RELOJ-ALARMA DEFINITIVO", 30,40);
text("hora actual--> "+horas+":"+minutos, 80,80);
button.draw();
if (!control_alarma)
{
fill(180,0,0);
textAlign(LEFT);
text("alarma NO activada", 80, 100);
}
if (control_alarma)
{
fill(0,180,0);
textAlign(LEFT);
text("sonará a las "+alarma[0]+":"+alarma[1], 80, 100);
}
// compara hora actual con la de la alarma
if(horas.equals(alarma[0])&& minutos.equals(alarma[1]) == true)
{
cancioncilla.volume(100);
cancioncilla.play();
//conectar con cochecito
fill(0,0,180);
textAlign(LEFT);
text("ahora suena", 80, 120);
}
}
void keyPressed()
{
//// let the button handle any keypresses
button.keyPressed();
}
void keyReleased()
{
//// let the button handle any keyreleases. this is
//// important as PButton sends its event on release!
button.keyReleased();
}
void libraryEvent(Object library, int event, Object data) {
if (library == button) {
//// if the button sent a library event, it was pressed!
guarda_alarma();
control_alarma = !control_alarma;
}
if (library == cancioncilla) {
text("suenas", 80,140);
}
}
Debemos añadir la parte de la transmisión bluetooth del programa y solucionar la excepción de java cuando acaba el archivo de audio. Estamos en ello!!!
2 comentarios:
asdfasdf
Guai!
Animo!!!!
Publicar un comentario