Connecting Arduino to Processing

Hello,

I hope this is the right place to post. I’m a beginner and I have been trying to fix this issue:

On Arduino I have a button that control what says on the lcd and controls the Servo. What I’m trying to do is to have random text to show on processing when you release the button. What am I doing wrong?

Right now on the processing side I only set it up to have a word “word” to appear. I still have to figure out how to get the random sentences I wrote in the set up.

sketch_nov30d.pde (1019 Bytes)

sketch_nov30d.ino (2.89 KB)

I’m sorry I didnt embed the code.

Here is the code on Arduino:

#include <Servo.h>  // add servo library

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 0;
const int colorG = 59;
const int colorB = 255;


Servo myServo;  // create servo object to control a servo
int servoPin = 5;

int buttonPin = 2;
int val;    // variable to read the value from the analog pin
int pos = 0;
long randNumber;
unsigned long count=0;
bool direction_up = true;
bool servo_direction = false; // true is up, flase is down;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  
  myServo.attach(servoPin);
  Serial.begin(9600);  

  // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    
    lcd.setRGB(colorR, colorG, colorB);
    
    // Print a message to the LCD.
    lcd.print("Spin the wheel!");

    delay(1000);
    randomSeed(analogRead(0));
}
void loop() 
{


    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    

    
    if(digitalRead(buttonPin)){
     
      myServo.write(pos);
      

    if(pos > 0 && pos < 180){
      if(servo_direction) {
        pos += 10;
      }
      else {
        pos -= 10;
      }
    }
    
    if(pos >= 180) {
      servo_direction = !servo_direction;
      pos -= 10;
    }
    if(pos <= 0){
      servo_direction = !servo_direction;
      pos += 10;
    }



      
    }

    

    if (BUTTON_PUSHED()) {
    randNumber = random(6);
    lcd.print(randNumber);//1000
    Serial.write(1);
    delay(100);
    }

    while (BUTTON_PUSHED()) continue;
  delay(50);                        
  count++;
  

 

}

int BUTTON_PUSHED() {
  if (digitalRead(buttonPin) == LOW) 
    return 1;                      
  return(0);
  digitalWrite(buttonPin, LOW);
  Serial.write(1);

  
}

Here is code in Processing:

import processing.serial.*;

Serial myConnection;
int val;
PFont myFont;

String[] word = new String[7]; //number of items

float background_color ;   // Variable for changing the background color

void setup() {
  size(600, 400);
  myConnection = new Serial(this, Serial.list()[1], 9600);
  myConnection.bufferUntil ( '\n' );
  
  myFont = createFont("Georgia", 32);
  
  word[0] = "Dance around the class";
  word[1] = "Take number of shown on lcd candies";
  word[2] = "Be wild";
  word[3] = "Say Arrete";
  word[4] = "Say the word Bottle number shown on wheel";
  word[5] = "Spin the wheel again";
  word[6] = "Pass the wheel to someone else";
  
}

void serialEvent  (Serial myConnection) {

background_color  =  float (myConnection.readStringUntil ( '\n' ) ) ;  // Changing the background color according to received data

} 


void draw(){
  background ( 150, 50, background_color );
  
  if (val == 1) {
    textFont(myFont);
    text("word", 12, 60);
    fill(0, 102, 153);
  textAlign(LEFT, TOP);
  
  }
  
}

Update:

I had forgotten to add "int val = analogRead(buttonPin);" in Arduino. So now it's working.

I just have to figure out the other part on processing which I dont think this is the forum for.