Hey! I’m new to Arduino and Processing I’m making a game and I want to play a certain sound when I or the CPU scores on Arduino.
I’m getting the error cannot convert from boolean to int I don’t know what I’m doing wrong I do know the score++ is not working.
import processing.serial.*; // Import the Processing Serial Library for communicating with arduino
import ddf.minim.*;
Minim minim;
AudioPlayer sound1, sound2, sound3, sound4;
Serial myPort;
int CPU_SCORE;
int PLAYER_SCORE;
boolean score = false;{
score++;
score = true;
}
void setup()
{
size(500, 500);
println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list)
myPort = new Serial(this, Serial.list()[1], 9600); // Open a new port and connect with Arduino at 9600 baud
minim = new Minim(this);
sound1 = minim.loadFile("roundLose.wav");
sound2 = minim.loadFile("gameLose.wav");
sound3 = minim.loadFile("gameWin.mp3");
sound4 = minim.loadFile("roundWin.wav");
}
void draw()
{
if(CPU_SCORE == 1 && score == true) {
sound1.play();
sound1.rewind();
score = false;
}
if(CPU_SCORE == 2 && score == true) {
sound1.play();
sound1.rewind();
score = false;
}
if(CPU_SCORE == 3 && score == true) {
sound1.play();
sound1.rewind();
score = false;
}
if(CPU_SCORE == 4 && score == true) {
sound1.play();
sound1.rewind();
score = false;
}
if(CPU_SCORE == 5 && score == true) {
sound1.play();
sound1.rewind();
score = false;
}
if(CPU_SCORE == 6 && score == true) {
sound1.play();
sound1.rewind();
score = false;
}
if(CPU_SCORE == 7 && score == true) {
sound1.play();
sound1.rewind();
score = false;
}
if(CPU_SCORE == 8 && score == true) {
sound2.play();
sound2.rewind();
score = false;
}
print(CPU_SCORE);
println(PLAYER_SCORE);
}
void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
if (myPort.available() > 1)
{
String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
if (completeString != null) // If there is valid data insode the String
{
trim(completeString); // Remove whitespace characters at the beginning and end of the string
String seperateValues[] = split(completeString, ","); // Split the string everytime a delimiter is received
CPU_SCORE = int(seperateValues[0]);
PLAYER_SCORE = int(seperateValues[1]);
}
}
}