Reading arrays from a text file (Please Help)!
in
Programming Questions
•
4 months ago
Hi
I'm having difficulties with reading an array from a text file (segg.txt) .
I will try to explain what i'm trying to do, but i am a complete programming noob :(.
So i have a text file with data in it that looks like this:
I'm having difficulties with reading an array from a text file (segg.txt) .
I will try to explain what i'm trying to do, but i am a complete programming noob :(.
So i have a text file with data in it that looks like this:
timepoint C C# D D# E F F# G G# A A# B
0.00
1.00 0.94 0.23 0.18 0.13 0.13 0.13 0.11 0.11 0.13 0.14 0.28
0.36 0.01 0.03 0.01 0.01 0.03 0.02 0.04 0.07 0.13
1.00 0.01 0.01
0.77
1.00 0.03 0.01 0.01 0.03 0.01 0.04 0.06 0.05 0.82 0.02 0.03
1.13
1.00 0.02 0.01 0.01 0.51 0.03 0.08 0.12 0.08 0.53 0.03 0.05
What i'm trying to accomplish is the following:
Each note (C, C#, D, D#, E, F, F#, G, G#, A, A#, B) i would like to link a led connected to an arduino (i have already uploaded the firmata to arduino).
When a note hits "1" at a certain point of time (timepoint) i would like the corresponding led to turn on. Offcourse this led turns off when the next note is playing.
I have found that i can read the text file with following code:
However this will just print out the entire text file, but it will not divide the array's parameters.
I REALLY hope someone can help me with this! :(
Here is some code that describes which arduino outputs i am using:
What i'm trying to accomplish is the following:
Each note (C, C#, D, D#, E, F, F#, G, G#, A, A#, B) i would like to link a led connected to an arduino (i have already uploaded the firmata to arduino).
When a note hits "1" at a certain point of time (timepoint) i would like the corresponding led to turn on. Offcourse this led turns off when the next note is playing.
I have found that i can read the text file with following code:
String[] lines = loadStrings("segg.txt");
println("there are " + lines.length + " lines");
for (int i=0; i < lines.length; i++) {
println(lines[i]);
}
However this will just print out the entire text file, but it will not divide the array's parameters.
I REALLY hope someone can help me with this! :(
Here is some code that describes which arduino outputs i am using:
- Arduino arduino;
- int trilmodule1 = 30;
- int trilmodule2 = 31;
- int trilmodule3 = 32;
- int trilmodule4 = 33;
- int trilmodule5 = 36;
- int trilmodule6 = 37;
- int trilmodule7 = 38;
- int trilmodule8 = 39;
- int trilmodule9 = 40;
- int trilmodule10 = 41;
- int trilmodule11 = 42;
- arduino = new Arduino(this, Arduino.list()[0], 57600);
- arduino.pinMode(trilmodule1, Arduino.OUTPUT);
- arduino.pinMode(trilmodule2, Arduino.OUTPUT);
- arduino.pinMode(trilmodule3, Arduino.OUTPUT);
- arduino.pinMode(trilmodule4, Arduino.OUTPUT);
- arduino.pinMode(trilmodule5, Arduino.OUTPUT);
- arduino.pinMode(trilmodule6, Arduino.OUTPUT);
- arduino.pinMode(trilmodule7, Arduino.OUTPUT);
- arduino.pinMode(trilmodule8, Arduino.OUTPUT);
- arduino.pinMode(trilmodule9, Arduino.OUTPUT);
- arduino.pinMode(trilmodule10, Arduino.OUTPUT);
- arduino.pinMode(trilmodule11, Arduino.OUTPUT);
- void resetSensors() {
- arduino.digitalWrite(trilmodule1, Arduino.LOW);
- arduino.digitalWrite(trilmodule2, Arduino.LOW);
- arduino.digitalWrite(trilmodule3, Arduino.LOW);
- arduino.digitalWrite(trilmodule4, Arduino.LOW);
- arduino.digitalWrite(trilmodule5, Arduino.LOW);
- arduino.digitalWrite(trilmodule6, Arduino.LOW);
- arduino.digitalWrite(trilmodule7, Arduino.LOW);
- arduino.digitalWrite(trilmodule8, Arduino.LOW);
- arduino.digitalWrite(trilmodule9, Arduino.LOW);
- arduino.digitalWrite(trilmodule10, Arduino.LOW);
- arduino.digitalWrite(trilmodule11, Arduino.LOW);
- // PARTICLE / PITCH (locatie van particle)
- // HIER VIBREREN
- if (physics.numberOfParticles() < MAX_PARTICLES ) {
- float yvel = map(constrain(size, 0, 140), 0, 140, 1, -10);
- int t = 0;
- for (int pitch = 0; pitch < 12; pitch++) {
- float pval = seg.getPitches()[pitch];
- if (pval > .25) {
- t++;
- println(pval);
- int numParticles = (int) (constrain(size * pval, 0, 50));
- for (int i = 0; i < numParticles; i++) {
- if(pval < 0.30 && pval > 0 ){
- resetSensors();
- arduino.digitalWrite(trilmodule1, Arduino.HIGH);
- } else if (pitch < 0.36 && pval > 0.30){
- resetSensors();
- arduino.digitalWrite(trilmodule2, Arduino.HIGH);
- } else if (pitch < 0.40 && pval > 0.36){
- resetSensors();
- arduino.digitalWrite(trilmodule3, Arduino.HIGH);
- } else if (pitch < 0.42 && pval > 0.40){
- resetSensors();
- arduino.digitalWrite(trilmodule4, Arduino.HIGH);
- } else if (pitch < 0.50 && pval > 0.42){
- resetSensors();
- arduino.digitalWrite(trilmodule5, Arduino.HIGH);
- } else if (pitch < 0.60 && pval > 0.50){
- resetSensors();
- arduino.digitalWrite(trilmodule6, Arduino.HIGH);
- } else if (pitch < 0.65&& pval > 0.60){
- resetSensors();
- arduino.digitalWrite(trilmodule7, Arduino.HIGH);
- } else if (pitch < 0.70 && pval > 0.65){
- resetSensors();
- arduino.digitalWrite(trilmodule8, Arduino.HIGH);
- } else if (pitch < 0.75 && pval > 0.70){
- resetSensors();
- arduino.digitalWrite(trilmodule9, Arduino.HIGH);
- } else if (pitch < 0.80 && pval > 0.75){
- resetSensors();
- arduino.digitalWrite(trilmodule10, Arduino.HIGH);
- } else if (pitch < 0.90 && pval > 0.80){
- resetSensors();
- arduino.digitalWrite(trilmodule11, Arduino.HIGH);
- } else if (pitch < 1.5 && pval > 0.90){
- resetSensors();
- // arduino.digitalWrite(trilmodule12, Arduino.HIGH);
- }
1