Skip to content
Snippets Groups Projects
Commit 0e392256 authored by Iryna Porokhovnichenko's avatar Iryna Porokhovnichenko
Browse files

Week 15 Update

parent 420d2947
No related branches found
No related tags found
No related merge requests found
Pipeline #508724 passed
src/assets/images/week15/board.jpg

197 KiB

src/assets/images/week15/board2.jpg

212 KiB

......@@ -145,6 +145,176 @@
</ul>
</li>
</ul>
<h3>Version #2</h3>
<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.
</p>
<div class="image-row2">
<figure class="image-container">
<img class="thumbnail" src='../assets/images/week15/board2.jpg' alt='boards'>
<figcaption>Microphone and Potentiometer connected to the board</figcaption>
</figure>
<figure class="image-container">
<img class="thumbnail" src='../assets/images/week15/board.jpg' alt='boards'>
<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>
<td rowspan="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>
<td rowspan="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,
serialString = myPort.readStringUntil('\n');
println(serialString);
if (serialString != null) {
if (serialString.startsWith("Pot value:")) {
String potValueString = serialString.substring("Pot value:".length()).trim();
potValue = int(potValueString);
} else if (serialString.startsWith("Analog microphine value:")) {
String microValueString = serialString.substring("Analog microphine value:".length()).trim();
microValue = int(microValueString);
}
}
println("Micro = " + microValue);
println("PIR = " + potValue);
}
startX = width/2;
startY = height/2;
drawPolygon(microValue, microValue * 5, potValue);
}
// draws polygon with n number of vertices, radius and on spectial X position
void drawPolygon(int n, float radius, int potX) {
float angleStep = TWO_PI / n;
fill(0, 255, 255);
stroke(0); // Black outline
strokeWeight(2); // Line thickness
beginShape();
for (int i = 0; i < n; i++) {
float x = (cos(i * angleStep) * radius) + potX;
float y = sin(i * angleStep) * radius + startY;
vertex(x, y);
}
endShape(CLOSE);
}
</code></pre>
<h4>Video presentation</h4>
<div>
<div class="image-row">
<figure class="image-container">
<video controls style="width: 550px">
<source src="../assets/images/week15/newApp.mp4" type="video/mp4">>
</video>
<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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment