I'm writing a where an object for example a rectangle moves from point A to point B.
As long as the two point declare an angle of 45° they move in a direct line. But if this angle isn't given anymore the object doesn't move anymore in a direct line, because the the xspeed and the yspeed is hardcoded, so the object starts to move in way looking like an "L". I hope this explains it good enough.
I can't show the sketch because it's an a differnt system without internetacces.
I'm trying to integrate the Arduino into my Processing sketches and it's kind of working , but not properly.
The idea is that when I press a button down, the Arduino sends a buttonspecific number, which is in this case 10 or 20, and then sends a 1 or a zero depending on the state of the button.
Now if I press one button, it prints out that both buttons have been pressed:
10
1
20
1
The Arduino Code:
int button1 = 4;
int button2 = 5;
int einser = 10;
int An = 1;
int Ab = 0;
int zweier = 20;
boolean eins = false;
boolean zwei = false;
void setup()
{
Serial.begin(9600);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
}
void loop()
{
if(digitalRead(button1) == HIGH && eins == false)
{
eins = true;
Serial.write(einser);
Serial.write(An);
//Serial.println("1");
}
else if(digitalRead(button1) == LOW && eins == true)
{
eins = false;
Serial.write(einser);
Serial.write(Ab);
}
if(digitalRead(button2) == HIGH && zwei == false)
{
zwei = true;
Serial.write(zweier);
Serial.write(An);
//Serial.println("2");
}
else if(digitalRead(button2) == LOW && zwei == true)
So i got this little code going on here and everything works right. but now i do want to put an automation in generating new objects, at where the program starts to fail, giving me the line:
ArrayIndexOutOfBoundsExeptions: 9
The program also highlights this line:
hallo[index++] = new Hello(geschwindigkeit, wahrfalsch);
Hello[] hallo;
boolean wahrfalsch;
float geschwindigkeit;
int anzahl = 9;
int index;
void setup()
{
size(500, 500);
frameRate(90);
background(255);
randomSeed(40);
hallo = new Hello[anzahl];
for(int b = 0; b <= anzahl; b++)
{
geschwindigkeit = random(8);
if (random(10) < 5) wahrfalsch = false;
hallo[index++] = new Hello(geschwindigkeit, wahrfalsch);