Angular processing software syntax error *float angle*

Angular processing software syntax error float angle

#include <Servo.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

Servo myservo;
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

int pos = 0;
const int trigPin = 9;
const int echoPin = 10;
const int moteur = 11;
const int buzzer = 12;
const int ledPin1 = 14;
const int ledPin2 = 15;
float distanceCm, DistanceSec, duration;

void setup() {
  Serial.begin(9600); // Initialize serial communication
  myservo.attach(moteur);
  lcd.init(); // Initialize the LCD
  lcd.backlight(); // Turn on the backlight
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  DistanceSec = 20;
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) {
 …
#Processing software code
import processing.serial.*;

Serial myPort;
float angle, distance;
int maxDistance = 100;

void setup() {
  size(800, 600);
  String portName = Serial.list()[0]; // Change this to the correct port number
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  background(0);
  translate(width / 2, height);
  
  // Draw radar arc
  noFill();
  stroke(0, 255, 0);
  arc(0, 0, width, width, PI, TWO_PI);
  
  // Draw distance circles
  for (int i = 1; i <= 4; i++) {
    float radius = (width / 2) * (i / 5.0);
    ellipse(0, 0, radius * 2, radius * 2);
    textAlign(RIGHT, CENTER);
    text(i * 25 + "cm", -5, -radius);
  }
  
  // Draw angle lines
  for (int i = 0; i <= 180; i += 30) {
    float x = (width / 2) * cos(radians(i));
    float y = (width / 2) * sin(radians(i));
    line(0, 0, x, -y);
    textAlign(CENTER, CENTER);
    text(i + "°", x, -y - 10);
  }
  
  // Draw radar line
  stroke(255, 0, 0);
  line(0, 0, (width / 2) * cos(radians(angle)), -(width / 2) * sin(radians(angle)));
  
  // Draw object
  if (distance > 0 && distance <= maxDistance) {
    float objectX = ((width / 2) * (distance / maxDistance)) * cos(radians(angle));
    float objectY = -((width / 2) * (distance / maxDistance)) * sin(radians(angle));
    fill(255, 0, 0);
    ellipse(objectX, objectY, 10, 10);
  }
  
  // Display angle and distance
  textAlign(LEFT, TOP);
  fill(255);
  text("Angle: " + int(angle) + "°", 10, 10);
  text("Distance: " + int(distance) + " cm", 10, 30);
}

void serialEvent(Serial myPort) {
  String data = myPort.readStringUntil('\n');
  if (data != null) {
    data = trim(data);
    String[] values = split(data, ',');
    if (values.length == 2) {
      angle = float(values[0]);
      distance = float(values[1]);
    }
  }
}
import processing.serial.*;

Serial myPort;
float angle = 0;
float distance = 0;
int maxDistance = 100;

void setup() {
  size(800, 600);
  println("Available serial ports:");
  printArray(Serial.list());
  
  // Pilih port serial yang sesuai
  String portName = Serial.list()[0]; // Ubah indeks jika perlu
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  background(0);
  
  // Basic visualization
  translate(width/2, height);
  stroke(0, 255, 0);
  line(0, 0, 
       (width/2) * cos(radians(angle)), 
       -(height/2) * sin(radians(angle)));
  
  // Display current values
  fill(255);
  textAlign(LEFT, TOP);
  text("Angle: " + angle, 10, 10);
  text("Distance: " + distance, 10, 30);
}

void serialEvent(Serial myPort) {
  try {
    String data = myPort.readStringUntil('\n');
    if (data != null) {
      data = trim(data);
      String[] values = split(data, ',');
      if (values.length == 2) {
        angle = float(values[0]);
        distance = float(values[1]);
      }
    }
  } catch (Exception e) {
    println("Error reading serial: " + e.getMessage());
  }
}

not clear what environment you're working in, is this Processing or Arduino.

don't understand what the above lines are intended to do

  • Arduino comments start with //, not #
  • Arduino uses #include not import
  • Arduino defines Serial as an instance of HardwareSerial

this block of code is missing braces, '}', and defines setup() again.

In addition to what @gcjr wrote, the code on the screenshot does not match the code you posted.

You shown:

but on the screen the first line is different:

Serial myPort; COM3
float angle = 0;