====== Livre interactif pour enfant avec capteur de pression ======
* **Porteur(s) du projet** : Vincent Rosier (DSAA 1), Damien MUTI (Prof. de Numérique)
* **Date** : 03/2021
* **Contexte** : Micro-projet de cours
* **Fichiers** :
* **Liens** : https://www.instructables.com/Interfacing-Force-Sensitive-Resistor-to-Arduino/ https://courses.ischool.berkeley.edu/i262/f13/content/sydmayes/lab-4-fsr-and-processing.html
* **Capteurs/Actionneurs** :
* Carte Arduino Uno /Seeduino
* Capteur de pression (force)
----
===== Intentions : explication du projet et objectifs =====
Dans le cadre d'une édition jeunesse, l'objectif est de réaliser un livre interactif afin de susciter la manipulation et de dynamiser la lecture de l'enfant. À l'aide d'un capteur de pression dissimulé dans une page, des sons et/ou formes seront générés sur Processing lorsque l'enfant appuieras sur celui-ci. Ces sons et/ou formes pourront varier en intensité (sonore / taille de la forme / couleur) ou bien se multiplier en fonction de la force transmise sur le capteur.
{{ :wiki:flossmanuals:livre-enfant-interactif-pression:flossmanual_schema_explicatif.jpg |}}
===== Plans et schémas de fonctionnement =====
. **Faire varier l'intensité d'une led ou d'une forme sur processing**
{{ :wiki:flossmanuals:livre-enfant-interactif-pression:plan_variation_intensite_led.png |}}
===== Programmes ARDUINO =====
==== Programme pour faire varier l'intensité d'une led ====
int fsrAnalogPin = 0; / FSR connecté a A0
int LEDpin = 11; / D11 pate de la LED
int fsrReading; / lecture du capteur FSR
int LEDbrightness;
void setup() {
// déclare ledPin comme une sortie numérique
Serial.begin(9600); // ouverture du port série
pinMode(LEDpin, OUTPUT);
}
void loop() {
fsrReading = analogRead(fsrAnalogPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);
/ Degrès d'intentsité de la luminosité de la LED
LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
// La LED devient plus brillante lorsqu'on appuie plus fort
analogWrite(LEDpin, LEDbrightness);
delay(100);
}
==== Programme pour envoyer UNE donnée via le port série ====
int firstSensor = 0; / first analog sensor
int inByte = 0; / incoming serial byte
void setup() {
// start serial port at 9600 bps:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop() {
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(A0)/4;
// send sensor values:
Serial.write(firstSensor);
delay(10); // patienter 10ms (à voir...)
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}
==== Programme final : mélange des deux programmes précédents ====
A COMPLETER
===== Programme PROCESSING =====
==== Variation forme graphique ====
import processing.serial.*;
int bgcolor[] = {255, 255, 255}; / Background color
int fgcolor =255; / Fill color
int xpos, ypos; / Starting position of the ball
int rayon = 20;
Serial myPort; / The serial port
int serialInArray; / Where we'll put what we receive
int serialCount = 0; / A count of how many bytes we receive
boolean firstContact = false; / Whether we've heard from the microcontroller
void setup() {
size(500, 500); // Stage size
noStroke(); // No border on the next thing drawn
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;
// Print a list of the serial ports, for debugging purposes:
printArray(Serial.list());
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
// espace HSB des couleurs
colorMode(HSB);
}
void draw() {
rectMode(CENTER);
background(0);
fill (255, 255, 200);
circle(xpos,ypos,rayon);
}
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();////////////////////////////////////////
// if this is the first byte received, and it's an A,
// clear the serial buffer and note that you've
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == 'A') {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
} else {
rayon= (int)map(inByte, 0,255,20,400);
// print the values (for debugging purposes only):
println("valeur lue sur le port Série = " + rayon);
// Send a capital A to request new sensor readings:
myPort.write('A');
}
}
===== Réalisation de la maquette =====
==== Images ====
{{ :wiki:flossmanuals:livre-enfant-interactif-pression:photos_capteur_pression.jpg |}}
==== Vidéos ====
* Faire varier l'intensité d'une LED : https://youtu.be/Ll94pqV1qZw
* Faire varier une forme graphique sur Processing : https://youtu.be/0GPNYONl8aM