I am trying to do a routine to use a keyboard as a data entry like : enter a file name or enter a string. So for, my code work until I don't know how to use the data inside my array to make a string. A string is a array of char, and I use the CR - Enter key - ASCII code 10 or 0x0A to control my program.
I want this : char mydataset[i] ----> String myword so I can use the string variable later to use as a file name by example or use print(myword) or text(myword,30,30) in my program.
Any help would be nice.
My code work except I use a for() loop to print(mydataset[i]) and I don't know to make my array of char into a string. And I use a state variable to control my program. I don't want something like : ttttttttttttttttttttttt
The code do is : show the key and ASCII code, the number of key typed, display in the console the key typed ( an echo ) and print the array. But no string yet.
I was just doing fiction solar system, the code did OK until the last new object in my code. For example : body_b.cx=body_a.x but when I did a println() the variable, the data is simply NOT equal... What the ???
Can somebody explain why the data ( romulus.x and moon_b.cx ) don't match ?
Go ahead, try it... the last object draw is going across the sceen instead of orbiting.
I am trying to do a program to simulate an ordit of a planet around a sun. My code work, but why it going slow and sudden speed-up ( reach near the top of the orbit ) and slow and speed-up ( reach near the bottom of the orbit ) and slow.....and repeat. The debug show me no problem in the calculation and the co-ordinates values to draw the orbit. Slow and Fast ... ? <-- I wonder why ? My computer is a 3 GHz Pentium Dual-Core... 1 GB Ram... humm ?
Anybody have any idea ?
The formula I use is from a math book and it is the circle formula. I use a 4 quadrant system ( use a switch() - case ) to figure out which quadrant my orbit is, so I simply count 0 to 50 and 50 to 0 and the quadrant is the state.
Here my code :
int x; int y; int r; // the radius of the orbit int xtemp; // the x and y to draw the planet on the screen int ytemp; float corx; // a float x
int state; // 4 state = 4 quadrant - think the x axis ( +/- ) and y axis ( +/- )
void setup() { size(400,400);
// init value r=50; y=0; xtemp=250; ytemp=200; state=1; }
void draw() { // The println is for debug println(xtemp+" "+ytemp+" "+x+" "+y); background(255); // draw a sun ellipse(200,200,50,50); // draw and calculate the planet position incircle(); ellipse(xtemp,ytemp,5,5);
}
// calculate the orbit position void incircle() { corx=sqrt(sq(r)-sq(y)); x=(int)corx;
// in which quadrant is the planet is switch(state) { case 1 :
I just finish a clock program. It show a digital and a analog clock. It use the time from your system and show the time in digital format ( 24 Hr ) and an analog format. I am new at Processing ( since mid-October 2011 ) I was trying to learn Processing and try something cool. I realize learning Processing required a lot of math, geometry, and programing. I am not a student, I am just an hobbyist ( electronics & computer ), I did programing before ( BASIC, Pascal, C, C++ , some assembly ), recently, Java and Java ME <-- for my cell phone ... I did 2 pratical program so far. And Processing. <-- I was "forced" to learn it because I was trying to send a file from my PC to my Arduino, and Procesing was the most easiest to use for that purpose. ( I still need a keyboard routine in Processing like a cin function or scanf() function )
Here my code and tell me of what you guys thinks...
I am trying to send a file through a serial port. ( to an Arduino ) It work ( sort of ) <-- RX light up..
But I received this message. Even there is nothing connecting to the serial port. COM1
Here the "error" message.
WARNING : RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
What is it ? And what I can do to correct it ? Program work fine. Except that error message.
Here my code : I modify the example code of loadBytes()
import processing.serial.*;
Serial myport;
void setup()
{
println(Serial.list()); myport = new Serial(this,Serial.list()[3], 9600); // My Arduino is COM7
// change the line --> myport = new Serial(this,Serial.list()[0],9600); // for COM1
// open a file and read its binary data byte b[] = loadBytes("curconv.rms");
int sz=b.length; println("The size of the file is : "+sz+"\n"); // print each value, from 0 to 255 for (int i = 0; i < b.length; i++) { // every tenth number, start a new line if ((i % 16) == 0) { println(); }
// bytes are from -128 to 127, this converts to 0 to 255 int a = b[i] & 0xff; print(hex(a,2) + " "); myport.write(a);