Skip to content
Snippets Groups Projects
Commit db14db40 authored by Louise Massacrier's avatar Louise Massacrier
Browse files

Update docs/Assignments/week13.md, docs/files/week13/ellipse-00.pde,...

Update docs/Assignments/week13.md, docs/files/week13/ellipse-00.pde, docs/files/week13/matrix00-OK.ino
parent 9c7e4026
Branches
No related tags found
No related merge requests found
Pipeline #358130 passed
......@@ -29,6 +29,8 @@ Here is what I had when connecting the matrix to Arduino (Serial Plotter) and us
Then, I connected it using Processing software. When using processing I struggled to find the right serial port. It was telling me the port was busy with a JBL GO or a Iphone despite the fact that I hadn't any of those with me... I checked on the port number of the USB modem on Arduino and it was the 7th ! so I just add this number on the line : String portName = Serial.list()[**7**]; aaand it worked ! Happy me :)
**Note** You can have a look at how many ports your computer have register in arduino > Tools > Port. The first port of the list is the number 0.
<iframe src="https://giphy.com/embed/wHQrgIW1RpblpiLd8k" width="480" height="232" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/wHQrgIW1RpblpiLd8k">via GIPHY</a></p>
### **Exploring the code on Processing**
......@@ -76,3 +78,4 @@ Materials : edible gold leaf, velostat and cling film for isolation
| **Softwares** | Arduino, Processing |
| **Tools** | Arduino Uno, Matrix |
| **Materials** | Conductive fabric/thread and piezoresistive fabric such as Velostat, ATtiny, capacitor, Resistor 220ohms, FTDI chip, LED... |
| **Files** | [Arduino code](../files/week13/matrix00-OK.ino), [Processing code](../files/week13/ellipse-00.pde) |
import processing.serial.*;
/*
Code based on Tom Igoe’s Serial Graphing Sketch
>> http://wiki.processing.org/w/Tom_Igoe_Interview
Reads X analog inputs and visualizes them by drawing a grid
using grayscale shading of each square to represent sensor value.
>> http://howtogetwhatyouwant.at/
Working with a matrix
*/
String myString = null;
String inString = null;
int lf = 10; // Linefeed in ASCII
Serial myPort; // The serial port
int rows = 2;
int cols = 2;
int maxNumberOfSensors = rows*cols;
float[] sensorValue = new float[maxNumberOfSensors]; // global variable for storing mapped sensor values,
float[] previousValue = new float[maxNumberOfSensors]; // array of previous values
int ellipseSize = 0;
int ellipseX;
void setup () {
size(600, 600); // set up the window to whatever size you want
ellipseSize = width/rows;
//println(Serial.list()); // List all the available serial ports
String portName = Serial.list()[8]; // set the number of your serial port!
myPort = new Serial(this, portName, 9600);
myPort.clear();
myPort.bufferUntil('\n'); // don’t generate a serialEvent() until you get a newline (\n) byte
background(0,0,255); // set inital background
smooth(); // turn on antialiasing
ellipseMode(CENTER); //define the position of the ellipse from its center
//ellipseMode(CORNER); //define the position of the ellipse from its corner
}
void draw () {
for (int i = 0; i < maxNumberOfSensors; i++) {
fill(sensorValue[i]-28,sensorValue[i]-28, sensorValue[i]-28); //Define first colour of the ellipse
ellipse(ellipseX + ellipseSize/2, ellipseSize * (i%rows) + ellipseSize/2, ellipseSize*(1-sensorValue[i]/255), ellipseSize*(1-sensorValue[i]/255)); //top left
if((i+1) % rows == 0) ellipseX += ellipseSize;
}
ellipseX=0;
}
void serialEvent (Serial myPort) {
inString = myPort.readStringUntil(lf); // get the ASCII string
println("test");
if (inString != null) { // if it’s not empty
inString = trim(inString); // trim off any whitespace
int incomingValues[] = int(split(inString, "\t")); // convert to an array of ints
if (incomingValues.length <= maxNumberOfSensors && incomingValues.length > 0) {
for (int i = 0; i < incomingValues.length; i++) {
// map the incoming values (0 to 1023) to an appropriate gray-scale range (0-255):
sensorValue[i] = map(incomingValues[i], 0, 1023, 0, 255); // stretch 5×5, because sensor value = 255 at rest (without pressure)
//incomingValue decreases with pressure because it is the resistance
sensorValue[i] = constrain(incomingValues[i], 0, 255); // stretch 5×5
println(sensorValue[i]); // print value to see
}
}
}
}
/*
Matrix: Kapton + Copper
A simple pressure sensor matrix made from two Kapton film sheets with
7×7 copper tape traces and a piece of Velostat or Eeonyx piezoresistive
material in between.
parsing through this grid by switching individual rows/columns to be
HIGH, LOW or INPUT (high impedance) to detect location and pressure.
>> http://howtogetwhatyouwant.at/
*/
#define numRows 2
#define numCols 2
#define sensorPoints numRows*numCols
int rows[] = {A0, A1};
int cols[] = {6,5};
int incomingValues[sensorPoints] = {};
void setup() {
// set all rows and columns to INPUT (high impedance):
for (int i = 0; i < numRows; i++) {
pinMode(rows[i], INPUT_PULLUP);
}
for (int i = 0; i < numCols; i++) { *
pinMode(cols[i], INPUT);
}
Serial.begin(9600);
}
void loop() {
for (int colCount = 0; colCount < numCols; colCount++) {
pinMode(cols[colCount], OUTPUT); // set as OUTPUT
digitalWrite(cols[colCount], LOW); // set LOW
for (int rowCount = 0; rowCount < numRows; rowCount++) {
incomingValues[colCount * numRows + rowCount] = analogRead(rows[rowCount]); // read INPUT
}// end rowCount
pinMode(cols[colCount], INPUT); // set back to INPUT!
}// end colCount
// Print the incoming values of the grid:
for (int i = 0; i < sensorPoints; i++) {
Serial.print(incomingValues[i]);
if (i < sensorPoints - 1)
Serial.print("\t");
}
Serial.println();
delay(10);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment