I linked my code to my Arduino and replaced the “keyPressed” buttons for the “arduino.HIGH”
However, currently when I press a button, it registers as multiple presses at once. I realize this could be very well the cause of putting it in the draw, but I’ve no clue how to link it like I did with the keyPressed function.
Please let me know if you need the full code, since I only put the main page down below to have a brief overview of the main problem.
Here’s my code:
import processing.serial.*;
import cc.arduino.*;
JSONArray values;
ArrayList<Moon> manen = new ArrayList<Moon>();
ArrayList<Clouds> wolken = new ArrayList<Clouds>();
Arduino arduino;
int buttonOne;
int buttonTwo;
int buttonThree;
int buttonFour;
Planet planeet;
Vessel spaceSat;
boolean planetSpawn = false;
boolean satSpawn = false;
PImage temp; //screenshot
int saveP = 1;
PImage matte;
float x = 500;
float y = 110;
float diameter = 600;
void setup() {
size(1600, 800);
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(7, Arduino.INPUT);
arduino.pinMode(8, Arduino.INPUT);
arduino.pinMode(6, Arduino.INPUT);
arduino.pinMode(5, Arduino.INPUT);
planeet = new Planet();
spaceSat = new Vessel();
matte = loadImage("matte.png");
}
void draw() {
background(0);
buttonOne = arduino.digitalRead(8);
buttonTwo = arduino.digitalRead(7);
buttonThree = arduino.digitalRead(6);
buttonFour = arduino.digitalRead(5);
planeet.planetSpawnHere();
for (Clouds b : wolken) {
b.cloudPuff();
}
image(matte, 0, 0); //obscure layer for clouds
for (Moon a : manen) {
//a.orbitLines();
a.whiteCirkel();
}
spaceSat.satSpawnHere();
if (buttonOne == arduino.HIGH) {
manen.add(new Moon(random(250, 380), random(20, 100), random(5, 45), random(0.002, 0.02), color(random(255), random(255), random(255))));
}
if (buttonTwo == arduino.HIGH) {
wolken.add(new Clouds(random(30, 75), random(15, 30), random(150, 600), random(250, 350), random(0, 10)));
}
if (buttonThree == arduino.HIGH) {
planeet.getRandom();
planetSpawn = true;
}
if (buttonFour == arduino.HIGH) {
spaceSat.getRandom();
satSpawn = true;
}
}
//void keyPressed() {
//if (buttonOne == arduino.HIGH) {
// manen.add(new Moon(random(250, 380), random(20, 100), random(5, 45), random(0.002, 0.02), color(random(255), random(255), random(255))));
//}
//if (buttonTwo == arduino.HIGH) {
// wolken.add(new Clouds(random(30, 75), random(15, 30), random(150, 600), random(250, 350), random(0, 10)));
//}
//if (buttonThree == arduino.HIGH) {
// planeet.getRandom();
// planetSpawn = true;
//}
//if (buttonFour == arduino.HIGH) {
// spaceSat.getRandom();
// satSpawn = true;
//}
//}
void keyTyped() {
if (key == 'x') {
PImage temp = get(415, 0, 770, 800);
temp.save("MyPlanet_" + saveP + ".png");
saveP++;
}
}