<div><p>I got a comment to prepare better photos of the scretch above, but as it was some time ago I couldn't do it, so I decided to write one more sketch.
This time I will also use the same microphone buth with Potentiometer, to control the visual image by myself too.
<figcaption>Mirophone and Potentiometer</figcaption>
</figure>
</div><h3>Component Connections for XIAO RP2040</h3>
<table>
<thead>
<tr>
<th>Component</th>
<th>Pin Name</th>
<th>Connected To (XIAO RP2040)</th>
</tr>
</thead>
<tbody>
<tr>
<tdrowspan="3">Microphone</td>
<td>GND</td>
<td>GND</td>
</tr>
<tr>
<td>3.3V</td>
<td>3.3V</td>
</tr>
<tr>
<td>Signal</td>
<td>A2</td>
</tr>
<tr>
<tdrowspan="3">Potentiometer</td>
<td>GND</td>
<td>GND</td>
</tr>
<tr>
<td>3.3V</td>
<td>3.3V</td>
</tr>
<tr>
<td>Signal</td>
<td>A3</td>
</tr>
</tbody>
</table>
<h4>Logic idea</h4><div> - I want to use the value from Microphone to draw something dynamically but at the same time be able to change the position along X Y-Axis
using Potentiometer.
<p>A potentiometer, often referred to as a "pot," is a type of variable resistor used to adjust the level of electrical resistance in a circuit. It has three terminals: two fixed pins and one adjustable pin, which is usually attached to a rotating or sliding knob or slider.</p>
<p>When the knob or slider is adjusted, the position of the adjustable pin changes, which alters the resistance between the two fixed pins. This allows to vary the voltage or current flowing through a circuit, making potentiometers useful for controlling things like volume in audio equipment or brightness in light dimmers.</p>
So I will use the potentiometer to change X axis value.
</div>
<h4>Board code for Arduino IDE</h4>
<pre><code>
#define MICRO_PIN A2 // microphone pin
#define POT A3 //pot pin
void setup() {
Serial.begin(9600);
pinMode(MICRO_PIN, INPUT);
pinMode(POT, INPUT);
}
void loop() {
int microValue = analogRead(MICRO_PIN); //reading microphone value
Serial.print("Analog microphine value:"); //sending it in a special message
Serial.println(microValue);
int pot = analogRead(POT); //readin potentiometer value
Serial.print("Pot value:");
Serial.println(pot);
delay(100);
}
</code></pre>
And <h4>Proccessing code:</h4>
<pre><code>
import processing.serial.*;
Serial myPort; // Create object from Serial class
static String serialString; // Data received from the serial port
int microValue = 0;
int potValue = 0;
int columnIndex = 0;
int maxRadius = 150;
int startX = width/2;
int startY = height/2;
float radius = 50; // Starting radius
float minRadius = 50; // Minimum radius
float speed = 2; // Speed of pulsation
float growth = speed; // Curren
void setup()
{
fullScreen(P3D);
noStroke();
String portName = "/dev/ttyACM0";// Change the number (in this case ) to match the corresponding port number connected to your Arduino.
println(Serial.list());
myPort = new Serial(this, portName, 9600);
translate(width / 2, height / 2);
}
void draw()
{
background(255);
if (myPort.available() > 0) { // If data is available,
<figcaption>You can see thow the figure changes it'ss</figcaption>
</figure>
</div>
</div>
</div>
<h3>Problems I had</h3>
<p>The main problem I had is that sometimes I wanted to work on that Processing part without the need to be connected with the board. And I found the solution.</p>
<p>With this solution, if we know the structure of data which is received or passed to the microcontroller board.</p>