13. Skin Electronics¶
Cyborg¶
Electronic class¶
Arduino vocab.¶
- PinMode () - Define if INPUT or OUTPUT
- Digital Read () - Read a value
- Digital Write () - Write a value
- Digital - Yes or No
- Analog - Range of value
- TONE - Sound, Vibration, ON
- NoTONE - OFF
- Delay () - Stop, Pause; Everything spause
- Millis () - Milliseconds, Horloge of Arduino (internally), counts from the time arduino is on. Multifunction something can continue. Ex: Every (1000) Bip, But other actions continue.
- Micros () - Microseconds (like millis)
- Random () - Gives random numbers (in between 2 and 5)
- Map () - To map range
- Serial.begin () - Start connectons with a dispositive (ex: computer and arduino)
- Serial.print () - See numbers in same lines
- Serial.println () - See numbers in different lines
- Read () - Send values from computer
- Serial.Available () - Receive the information. Ex: If S.avai (if you receive a value) then S.read (then play)
How to code¶
Piano Skin¶
Code¶
// Import the CapacitiveSensor Library.
#include <CapacitiveSensor.h>
#define speaker 11
// Set the Send Pin & Receive Pin.
CapacitiveSensor cs_2_3 = CapacitiveSensor(2,3);
CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
CapacitiveSensor cs_2_5 = CapacitiveSensor(2,5);
void setup()
{
// Arduino start communicate with computer.
Serial.begin(9600);
}
void loop()
{
// Set a timer.
long start = millis();
// Set the sensitivity of the sensors.
long total1 = cs_2_3.capacitiveSensor(1000);
long total2 = cs_2_4.capacitiveSensor(1000);
long total3 = cs_2_5.capacitiveSensor(1000);
Serial.println(total1); // print sensor output 1
Serial.print("\t"); // Leave some space before print the next output
Serial.println(total2); // print sensor output 1
Serial.print("\t"); // Leave some space before print the next output
Serial.println(total3); // print sensor output 1
Serial.print("\t"); // Leave some space before print the next output
// When hand is touched the sensor, the speaker will produce a tone.
// I set a threshold for it, so that the sensor won't be too sensitive.
if (total1 > 500) tone(speaker,131); // frequency
if (total2 > 500) tone(speaker,350); // frequency
if (total3 > 500) tone(speaker,550); // frequency
// When hand didn't touch on it, no tone is produced.
if (total1<=500 & total2<=500 & total3<=500)
noTone(speaker);
delay(500); // arbitrary delay to limit data to serial port
}
Week 13 - Test piano from Amaya de Yavorsky on Vimeo.