Created
November 19, 2020 21:12
-
-
Save magdesign/52b9c6affaf00d88e9d561117d07f606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this is a countdown which takes its time from an input file | |
but it does not work yet....scratching my head... how the hell could | |
I make a valueinput when starting the compiled processing programm, | |
would love to launch with a flag containing the seconds like: sketch_contdown02 -300 | |
*/ | |
///load time from a file, decalred as data | |
int[] timer; | |
//int giventime = 6000; //set seconds to count down, should be replace with the output of file content | |
//int timer = giventime //just a workaround to get reset on click working | |
int bgcolor = 0; //for a faster color change | |
void setup(){ | |
//make it fullscreen later on with | |
//fullScreen(); //fullscreen | |
size(800,800); //small view | |
frameRate (30); //RPi can't handle more than approx. 35fps | |
//sets the time from the file | |
String[] txtFile = loadStrings("/home/magdesign/Desktop/data.txt"); | |
timer = new int[txtFile.length]; | |
//this just print the value, but does not set it ;( | |
for (int i = 0; i != timer.length; println()) | |
println( timer[i] = int((txtFile[i++])) ); | |
} | |
void draw(){ | |
background(bgcolor); | |
textAlign(CENTER, CENTER); | |
textSize((width/5)); | |
///////////////////////////// | |
///here we make sure its always displayed in 00:00:00 format | |
//here we add 0 ifront of seconds | |
String finalseconds = nf((timer %60),2); | |
//here we add 0 to minutes | |
String finalminutes = nf(((timer/60)%60),2); | |
//add 0 to hours | |
String finalhours = nf(((timer/360)%60),2); | |
///////////////////////////// | |
//here we display counter: | |
text(finalhours+":"+finalminutes+":"+finalseconds, (width/2), height/2); | |
////////////////////////////// | |
// here is the main counter programm: | |
if(frameCount%30==0 && timer>0){//if frameCount is divided by 60 = 1 second | |
//and also stop timer when we reach 0 | |
timer=timer-1; | |
} | |
if (timer == 0){ | |
delay(1); | |
background(bgcolor); | |
text("lets beginn",width/2, height/2 ); | |
//this will trigger a script | |
//launch("/here I need to enter the sys command"); | |
} | |
} | |
/////////////////////////////////// | |
//resets to start when mouse is clicked: | |
void mouseClicked(){ | |
//when moue is clicked, countdown will start again | |
//add gpio pins for buttons or mouse | |
//background(125); | |
timer=giventime; | |
setup(); | |
} |
This is brilliant timer = int(txtFile[0]);
thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//Have a look - it works on my computer also as a stand alone application;)
///load time from a file, decalred as data ( you don't need an array, as there is just one value to pick )
int timer;
/// declare the String Array to store the data from the txt file
String[] txtFile;
//int giventime = 6000; //set seconds to count down, should be replace with the output of file content
//int timer = giventime //just a workaround to get reset on click working
int bgcolor = 0; //for a faster color change
void setup(){
//make it fullscreen later on with
//fullScreen(); //fullscreen
size(800,800); //small view
frameRate (30); //RPi can't handle more than approx. 35fps
//sets the time from the file
txtFile = loadStrings("/home/magdesign/Desktop/data.txt");
// here you basically need to assign the first and only item of the string array "txtFile" to the int "timer"
// you need to write int( string ) to convert a string into an integer
timer = int(txtFile[0]);
/*
timer = new int[txtFile.length];
with this command line you're not assigning a value to "timer",
but you're initialising the new array of integer numbers called "timer"
and declaring that it's as long as the array "txtFile"
*/
//this just print the value, but does not set it ;(
// for (int i = 0; i != timer.length; println())
println( timer );
}
void draw(){
background(bgcolor);
textAlign(CENTER, CENTER);
textSize((width/5));
/////////////////////////////
///here we make sure its always displayed in 00:00:00 format
//here we add 0 ifront of seconds
String finalseconds = nf((timer%60),2);
//here we add 0 to minutes
String finalminutes = nf(((timer/60)%60),2);
//add 0 to hours
String finalhours = nf(((timer/360)%60),2);
/////////////////////////////
//here we display counter:
text(finalhours+":"+finalminutes+":"+finalseconds, (width/2), height/2);
//////////////////////////////
// here is the main counter programm:
if(frameCount%30==0 && timer>0){//if frameCount is divided by 60 = 1 second
//and also stop timer when we reach 0
timer=timer-1;
}
if (timer == 0){
delay(1);
background(bgcolor);
text("lets beginn",width/2, height/2 );
//this will trigger a script
//launch("/here I need to enter the sys command");
}
}
///////////////////////////////////
//resets to start when mouse is clicked:
void mouseClicked(){
//when moue is clicked, countdown will start again
//add gpio pins for buttons or mouse
//background(125);
timer=int(txtFile[0]);
setup();
}