Skip to content

W08. WEARABLES

Starting a new week with ELECTRONICS embeded into WERABLES.

CHECK LIST

  • -> Document the concept/ sketches/ references/ artistic & scientific publications

  • ->Create a swatch/sample using an ATTiny/Arduino/Adafruit with one input and one output, using hard-soft connection solutions and battery

  • ->Create 2 actuator swatches

  • ->Program Arduino/ATTiny/Adrafruit, documenting process,libraries added, power requirements and source code

  • ->Document scheme & circuit

  • ->Upload a small video of your object working

INSPIRATIONS

REFS1

1/Clara Daguin, 2/BROCHIER technologies 3/Wearable media

Body Electric by Clara Daguin

Brochier Technologies

French company from Lyon known for silk waeving and new tech REFS2

Neo Noir by Superficial Studio/ Wearable Media

Google Jacquard

Re-FREAM project "Second Skins" by Malou Beemer

Like a Pearl in my Hand Carina Hesper

Some More

STEPbySTEP WEARABLES

Stepbystep

DRIVER CIRCUIT

It is a circuit that allows to control a Power Load with low Voltage.

Circuitdriver

MOFSET

ACTUATORS

-> VISUAL

--LED - ARDUINO CODING - MOFSET CIRCUIT DRIVER------------------------

Stepbystep

02_Led_Analogwrite 03_read_digialsensor
led arduino Led arduino soft sensor
Analog readsensor
06_array-led-switch
1Arrayledswitch
2Arrayledswitch Arrayledswitch

Arduinosketches.
01_blink_led.ino
/*Emma Pareschi 25 Spetmber 2017
 * I turn on a led and I turn it off
 */

int led_pin = 3; //defin the pin where the Led is connected

void setup() {

  pinMode(led_pin, OUTPUT); //define pin of the Led as an output

}

void loop() {

  digitalWrite(led_pin, HIGH); //turn the Led on
  //digitalwrite(pin, HIGH/LOW)
  //HIGH=> 5V
  //LOW=> 0V
  delay(1000);                 //wait 1000millisecond 
  digitalWrite(led_pin, LOW);  //turn the Led off 
  delay(1000);                 //wait 1000millisecond

}
02_led_analogwrite.ino
/*Emma Pareschi 25 Spetmber 2017
 * I change the intensity of the Led
 */

int led_pin = 3; //defin the pin where the Led is connected

void setup() {

  pinMode(led_pin, OUTPUT); //define pin of the Led as an output

}

void loop() {

  //analogWrite(pin, 0/255);
  analogWrite(led_pin, 255); //set max intensity   
  delay(1000);                 //wait 100millisecond 
  analogWrite(led_pin, 190); 
  delay(1000);                 //wait 100millisecond 
  analogWrite(led_pin, 127); //set half intensity
  delay(1000);                 //wait 100millisecond
  analogWrite(led_pin, 50);   
  delay(1000);                 //wait 100millisecond 
  analogWrite(led_pin, 0); //set min intensity
  delay(1000);                 //wait 100millisecond

}
03_read_DigitalSensor.ino
/*Emma Pareschi
 * we read the value of a digital sensor connected to pin digital_sensor_pin and
 * we print it on the Serial Monitor
 */

int digital_sensor_pin = 2;     //change the pin, where the sensor is connected
int digital_sensor_value = 0;   //variable in which we save the sensor voltage

void setup() {
  // put your setup code here, to run once:
  //pinMode(digital_sensor_pin, INPUT);
  pinMode(digital_sensor_pin, INPUT_PULLUP); //define the pin as INPUT
  Serial.begin(9600); //open communication

}

void loop() {
  // put your main code here, to run repeatedly:
  // digitalRead(pin);
  digital_sensor_value = digitalRead(digital_sensor_pin); // read the sensor 

  Serial.print("the status of the sensor is: ");
  Serial.println(digital_sensor_value); //print the value
  delay(100);

}
04_button_led.ino
/*Emma Pareschi,
 * this skecth is a modification of the example button!!
 */

int digital_sensor_pin = 2;     //change the pin, where the sensor is connected?
int digital_sensor_value = 0;   //variable in which we save the sensor voltage
int led_pin = 3; //change the pin of the Led

void setup() {
  // put your setup code here, to run once:
  pinMode(digital_sensor_pin, INPUT_PULLUP);  //initialize the sensor pin
  pinMode(led_pin, OUTPUT);   //initialize led pin
  Serial.begin(9600);

}

void loop() {
  digital_sensor_value = digitalRead(digital_sensor_pin); //read the Voltage at pin sensor

//if the switch is pressed then the led turns on
//otherwise is not pressed


  // check if the pushbutton is pressed. 
  if(digital_sensor_value == LOW){    //If it is NOT pressed

      digitalWrite(led_pin, HIGH);     // turn the LED on


      Serial.println("the Led is on.");

  } else {                             //If it is pressed

      digitalWrite(led_pin, LOW);    // turn the LED on by setting the voltage HIGH

  }  

}
05_counter.ino
/*
Emma Pareschi October 2018
I count the times the push button is pressed and I reset the count
 */

// this constant won't change:
int sw_pin = 2;    // the pin that the pushbutton is attached to
int counter_reset = 5; //variable to reset the counter

// Variables will change:
int counter = 0;   // counter for the number of button presses
int sw_status = 0;         // current state of the button
int last_sw_status = 1;     // previous state of the button

void setup() {
  pinMode(sw_pin, INPUT_PULLUP);    // initialize the button pin as a input
  Serial.begin(9600);     // initialize serial communication
}

void loop() {

  // read the pushbutton input pin:
  sw_status = digitalRead(sw_pin);


  // compare the switch status to its previous state
  if (sw_status != last_sw_status) {  //if the status of the Led is different from the last time

    if(sw_status == HIGH){        //if the status is HIGH, the switch was relaised
      counter = counter + 1;    //increase the counter of 1 unit
    }

    // Delay a little bit to avoid bouncing
    delay(50);
  }

  Serial.print("Counter: ");    //print on Serial monitor the counter value
  Serial.println(counter);

  last_sw_status = sw_status;   //set the last status

  if (counter == counter_reset){ // if the counter is equal to the counter reset
    counter = 0;    // set the counter to zero again
    }

}
06_led_on_off.ino
/*
Emma Pareschi 2020
I count the times the push button is pressed
 */

// this constant won't change:
int  sw_pin = 2;    // the pin that the pushbutton is attached to
int counter_reset = 2; //variable to reset the counter

int led_pin = 3; //pin of the led

// Variables will change:
int counter = 0;   // counter for the number of button presses
int sw_status = 0;         // current state of the button
int last_sw_status = 1;     // previous state of the button

void setup() {
  // initialize input and output pins:
  pinMode(sw_pin, INPUT_PULLUP);
  pinMode(led_pin, OUTPUT);

  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {

  // read the pushbutton input pin:
  sw_status = digitalRead(sw_pin);

  // compare the switch status to its previous state
  if (sw_status != last_sw_status) {   
    if(sw_status == HIGH){     //if the status is HIGH, the switch was relaised
      counter = counter + 1;   //increase the counter of 1 unit
    }   
    // Delay a little bit to avoid bouncing
    delay(50);
  }

  Serial.print("Counter: ");  //print on Serial monitor the counter value
  Serial.println(counter);

  last_sw_status = sw_status;   //set the last status

  if (counter == counter_reset){
    counter = 0;
    }

  if (counter == 0){             //if the counter is ZERO
    digitalWrite(led_pin, LOW);  //Led if off
  } else {                        //otherwise (if it is 1)
    digitalWrite(led_pin, HIGH);
   }
}
07_array_led_switch.ino
/*
Emma Pareschi 2020
I turn on the Leds based on the times I press the digital switch
 */

// this constant won't change:
int  sw_pin = 2;    // the pin that the pushbutton is attached to
int counter_reset = 4; //variable to reset the counter

int array_led[] = {3,5,6};  //array of led
int num_leds = 3;

// Variables will change:
int counter = 0;   // counter for the number of button presses
int sw_status = 0;         // current state of the button
int last_sw_status = 1;     // previous state of the button

void setup() {
  // initialize input and output pins:
  pinMode(sw_pin, INPUT_PULLUP);

  //set the array pins as output
  for(int i = 0; i < 4; i = i+1){
    pinMode(array_led[i], OUTPUT);
  }

  // initialize serial communication:
  Serial.begin(9600);
}

void loop() {

  // read the pushbutton input pin:
  sw_status = digitalRead(sw_pin);

  // compare the switch status to its previous state
  if (sw_status != last_sw_status) {   
    if(sw_status == HIGH){     //if the status is HIGH, the switch was relaised
      counter = counter + 1;   //increase the counter of 1 unit
    }   
    // Delay a little bit to avoid bouncing
    delay(50);
  }

  Serial.print("Counter: ");  //print on Serial monitor the counter value
  Serial.println(counter);

  last_sw_status = sw_status;   //set the last status

  //if the switch as been pressed
  //turn on the Leds based on the counter
  if(counter != 0){

    for(int i = 0; i < counter; i = i+1){
      digitalWrite(array_led[i], HIGH);
    } 

    for(int i = counter+1; i < num_leds+1; i = i+1){
      digitalWrite(array_led[i], LOW);
    }

  } else {
    for(int i = 0; i < num_leds+1; i = i+1){
      digitalWrite(array_led[i], LOW);
    }
  }

  //reset the counter
  if (counter == counter_reset){
    counter = 0;
  }
}

------------------------------NeoPixels-------------------------------

Neopixelsketches.
03_Rainbow.ino
//Emma Pareschi 2020
//Adaptation of the example Standtest

#include <Adafruit_NeoPixel.h>

#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 10

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

uint32_t off = strip.Color(0, 0, 0);
int num_rainbow = 1;

void setup() {

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}

void loop() {

  rainbow(10);             // Flowing rainbow cycle along the whole strip

  //strip.fill(off, 0, 10);  // turn the strip off
  //strip.show();  //display the color 
  //delay(1000);

}




// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {

  for(long firstPixelHue = 0; firstPixelHue < num_rainbow*65536; firstPixelHue += 256) {
    for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());

      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    strip.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment
  }
}
06_rainbow_analogsensor.ino
#include <Adafruit_NeoPixel.h>

// Which pin on the microcontroller board is connected to the NeoPixels?
#define PIN             6  // For Circuit Playground Express

// How many NeoPixels are attached to the board?
#define NUMPIXELS      10

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 500; // delay for half a second

// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
const int sensorPin = A0;    // pin that the sensor is attached to

int pixelHue = 0;
int pixelHue_delta =0;

void setup() {
  Serial.begin(9600);
  pixels.begin(); // This initializes the NeoPixel library.
  pixels.show();            // Turn OFF all pixels ASAP
  pixels.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)

   // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);

  // calibrate during the first five seconds
  while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);

    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }

    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }

  // signal the end of the calibration period
  digitalWrite(13, LOW);
}


void loop() {
   int i;              // loop variable
   int value;          // analog read of potentiometer
   int display_value;  // number of NeoPixels to display out of NUMPIXELS

   // Read PIN value and scale from 0 to NUMPIXELS -1
   value = analogRead(A0);
   Serial.print(value);
   Serial.print(" - ");
   value = map(value, sensorMin, sensorMax, 0, NUMPIXELS);
   display_value = constrain(value, 0, NUMPIXELS);
   Serial.println(display_value);

   // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one
  pixelHue_delta = 65536/(NUMPIXELS+1);

   for(i=0; i<display_value; i++){
        pixels.setPixelColor(i, pixels.gamma32(pixels.ColorHSV(i*pixelHue_delta)));
        //Serial.println(i*pixelHue_delta);
   }  
   for(i=display_value; i<NUMPIXELS; i++) {
      pixels.setPixelColor(i, 0, 0, 0);    // turn off all pixels after value displayed
   }

   pixels.show(); // This sends the updated pixel color to the hardware.

   delay(delayval); // Delay for a period of time (in milliseconds).
}
08_melody.ino
/*

  Melody

  Plays a melody

  circuit:

  - 8 ohm speaker on digital pin 8

  created 21 Jan 2010

  modified 30 Aug 2011

  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Tone

*/

#include "pitches.h"

// notes in the melody:
int melody[] = {

  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {

  4, 8, 8, 4, 4, 4, 4, 4
};

//vaiable speaker pin
const int speaker = 3; //buzzer to arduino pin 3

void setup() {

  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

    int noteDuration = 1000 / noteDurations[thisNote];
    tone(speaker, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:

    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);

    // stop the tone playing:
    noTone(8);

  }
}

void loop() {
  // no need to repeat the melody.
}
09_starwars_v1.ino
/* 
  Imperial March - Star Wars
  Connect a piezo buzzer or speaker to pin 11 or select a new pin.
  More songs available at https://github.com/robsoncouto/arduino-songs                                            

                                              Robson Couto, 2019
*/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0


// change this to make the song slower or faster
int tempo = 120;

// change this to whichever pin you want to use
int buzzer = 3;

// notes of the moledy followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int melody[] = {

  // Dart Vader theme (Imperial March) - Star wars 
  // Score available at https://musescore.com/user/202909/scores/1141521
  // The tenor saxophone part was used

  NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
  NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
  NOTE_A4,4, NOTE_A4,4, NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16,

  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,//4
  NOTE_E5,4, NOTE_E5,4, NOTE_E5,4, NOTE_F5,-8, NOTE_C5,16,
  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,

  NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 
  NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,

  NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
  NOTE_C5,4, NOTE_A4,-8, NOTE_C5,16, NOTE_E5,2,

  NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 
  NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,

  NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,

};

// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;

// this calculates the duration of a whole note in ms
int wholenote = (60000 * 4) / tempo;

int divider = 0, noteDuration = 0;

void setup() {
  // iterate over the notes of the melody. 
  // Remember, the array is twice the number of notes (notes + durations)
  for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzer, melody[thisNote], noteDuration*0.9);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);

    // stop the waveform generation before the next note.
    noTone(buzzer);
  }
}

void loop() {
  // no need to repeat the melody.
}
10_starwars_digitalsensor.ino
/* 
  Imperial March - Star Wars
  Connect a piezo buzzer or speaker to pin 11 or select a new pin.
  More songs available at https://github.com/robsoncouto/arduino-songs                                            

                                              Robson Couto, 2019
*/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0


// change this to make the song slower or faster
int tempo = 120;

// change this to whichever pin you want to use
int buzzer = 3;

// notes of the moledy followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int melody[] = {

  // Dart Vader theme (Imperial March) - Star wars 
  // Score available at https://musescore.com/user/202909/scores/1141521
  // The tenor saxophone part was used

  NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
  NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
  NOTE_A4,4, NOTE_A4,4, NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16,

  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,//4
  NOTE_E5,4, NOTE_E5,4, NOTE_E5,4, NOTE_F5,-8, NOTE_C5,16,
  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,

  NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 
  NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,

  NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
  NOTE_C5,4, NOTE_A4,-8, NOTE_C5,16, NOTE_E5,2,

  NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7 
  NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,

  NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
  NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,

};

// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;

// this calculates the duration of a whole note in ms
int wholenote = (60000 * 4) / tempo;

int divider = 0, noteDuration = 0;

//variable for the senor
int sensor_pin = 7;
int sensor_value = 0;

void setup() {

  pinMode(sensor_pin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {

  //read and save the sensor voltage
  sensor_value = digitalRead(sensor_pin);
  Serial.println(sensor_value);

  if(sensor_value == LOW){  //if the sensor is pressed
      play_melody();  //play the melody
  }

}

void play_melody(){
    // iterate over the notes of the melody. 
  // Remember, the array is twice the number of notes (notes + durations)
  for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzer, melody[thisNote], noteDuration*0.9);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);

    // stop the waveform generation before the next note.
    noTone(buzzer);
  }
}
neopixel_switch_diane.ino
#include <Adafruit_NeoPixel.h>
// A basic everyday NeoPixel strip test program.

// NEOPIXEL BEST PRACTICES for most reliable operation:
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
//   connect GROUND (-) first, then +, then data.
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
//   a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
// (Skipping these may work OK on your workbench but can fail in the field)

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 4

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

int sw_pin = 2;

// Variables will change:
int sw_status = 0;         // current state of the button
int delayval = 1000; // delay for half a second


// setup() function -- runs once at startup --------------------------------

void setup() {

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)

  pinMode(sw_pin, INPUT_PULLUP);
  Serial.begin(9600);

}


// loop() function -- runs repeatedly as long as board is on ---------------

void loop() {

   sw_status = digitalRead(sw_pin);
   Serial.println(sw_status);

   if (sw_status == 0){
      strip.clear();
      Serial.println("coucou");

      strip.setPixelColor(0, 255, 180, 0); //set the color red on the first pixel
      strip.show();  //display the color 
      delay(delayval);

      strip.setPixelColor(1, 0, 255, 50); //set the color green on the first pixel
      strip.show();  //display the color 
      delay(delayval);

      strip.setPixelColor(2, 0, 100, 255); //set the color green
      strip.show();  //display the color 
      delay(delayval);

      strip.setPixelColor(3, 100, 0, 255); //set the color green
      strip.show();  //display the color 
      delay(delayval);

    } else {
      strip.clear();
      strip.show();
    }
}

Neopixels

USEFUL LINKS - Neopixel connections - ConvertUnits - Neopixel Arduino Library - Neopixel Effect Generator - Neopixel Algorithms

---------------------Thermochromic inks-------------------------------

Stepbystep

Stepbystep

-> SOUND

--------------------------------Speakers------------------------------

-> MOTION

--------------------------Flip dots, sma,Vibrating motor--------------

Fuxus Nitinol Fuxus Nitinol

Flip dots Flip dots

TUTORIALS

Helpful Alumni

SUPPLIERS


Last update: 2022-06-21