How is a circle appeared when the Piezo sensor is moved?

I trie to write a code like this, but it does not work.

import processing.serial.*;

import org.firmata.; import cc.arduino.;

Arduino arduino;

int S1 = 0; int A; void setup() { size(500, 500); ellipseMode(CENTER);

arduino = new Arduino(this, Arduino.list()[0], 57600);

arduino.pinMode(S1, Arduino.INPUT); }

void draw() {

A = arduino.analogRead(S1); println(A); if (A ==1) { ellipse(width/2,height/2,100,100); } }

It looks like the circle should appear if the analog input read from pin A0 is exactly 1. That would be about 4.883 millivolts.

Pinset is also right.

papa1963: Pinset is also right.

No idea that you are asking/saying here.

You have defined the pin to be a digital input pin, but are reading from it as though it was an analog pin.

try

void draw() {
  
   A = arduino.analogRead(S1);
  println(A);
  if (A >=1) {
   ellipse(width/2,height/2,100,100);
  }
}

analogRead can give you a value between 0 ~ 1024

what is displayed with the println(A);

@papa1963: Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Your other two, almost identical, threads deleted.

  • Moderator

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” icon above the posting area. It is the first icon, with the symbol: </>

Please use code tags.

Read this before posting a programming question

How to use this forum