Fundamentals of Soft Prototyping

Communication Design Project Winter Semester 2018/2019
Rhine-Waal University of Applied Sciences FabLab Kamp-Lintfort
by Adriana Cabrera

Paper Electronics 2

In the following links you can find the second part of the Paper Electronics Session

“Jingle Bell” melody

In the following CODE you can find song “Jingle Bell” melody

            
            /*
  Melody

  Plays the “Jingle Bell” melody and blink and LED to the melody

*/ -->

#include "pitches.h"

#define LOUDSPEAKER 0
#define LED 1

// notes for "Jingle Bell" melody
int melody[] = {
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5,
  NOTE_E5,
  NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
  NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5,
  NOTE_D5, NOTE_G5
};
int tempo[] = {
  8, 8, 4,
  8, 8, 4,
  8, 8, 8, 8,
  2,
  8, 8, 8, 8,
  8, 8, 8, 16, 16,
  8, 8, 8, 8,
  4, 4
};

void setup() {
  pinMode(LOUDSPEAKER, OUTPUT);
  pinMode(LED, OUTPUT);
  playTone();

}

void loop() {
  // no need to repeat the melody.
}

void playTone(){
  int size = sizeof(melody) / sizeof(int);
  for (int thisNote = 0; thisNote < size; 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 / tempo[thisNote];
    playNote(LOUDSPEAKER, melody[thisNote], noteDuration);
    playNote(LED, 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:
    playNote(LOUDSPEAKER, 0, noteDuration);
    playNote(LED, 0, noteDuration);
*/
  }
}


void playNote(int targetPin, long frequency, long length){
    long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
    //// 1 second's worth of microseconds, divided by the frequency, then split in half since
    //// there are two phases to each cycle
    long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
    //// multiply frequency, which is really cycles per second, by the number of seconds to
    //// get the total number of cycles to produce
    for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
      digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
      delayMicroseconds(delayValue); // wait for the calculated delay value
      digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
      delayMicroseconds(delayValue); // wait again or the calculated delay value
    }

}

            
            
            

Instructions

  1. Open the > Sketch > Examples > tone Melody

  2. Erase the part of the first sketch and past the skectch that is in the following part

  3. verify the right configuration from the Attiny85 under the menu tools and double check the connections

  4. Run the sketch using the option "uploading using Programmer"

Assignment

  • You will Program your card and you will bring your functional Prototype to the class combinig the asthetics part to the funtional part
  • Best cards will be selected as patterns for the workshops of Christmas "Basteln Aktion" Employees of the Rhine-Waal University of Applied Sciences.
  • FabLab Kamp-Lintfort