Grove starter kit for arduino --- Buzzer

by Grant

  • 398 views
  • 0 comments
  • 4 respects

Grove Starter Kit for Arduino --- Light Sensor

by Grant

  • 1,137 views
  • 0 comments
  • 2 respects


Servo

by Grant

  • 13,606 views
  • 14 comments
  • 39 respects

Relativ - Build Your Own VR Headset for $100

Project showcase by Relativty

  • 29,537 views
  • 19 comments
  • 107 respects

Master Slave I2C Connection

by PIYUSH_K_SINGH

  • 8,788 views
  • 0 comments
  • 10 respects

  • Piezo "happy birthday" 10 months ago

    I fixed it:
    (and tried it so I know this works)

    int speakerPin = 9;
    int length = 26; // the number of notes
    char notes[] = "aabacdaabaecaahfcndbggfcec "; // a space represents a rest
    int beats[] = {2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 8, 2, 2, 4, 4, 4, 4, 0, 4, 3, 1, 4, 4, 4, 8, 16 };
    int tempo = 75;

    void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
    }
    }
    void playNote(char note, int duration) {
    char names[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'n' };
    int tones[] = { 1515, 1351, 1136, 1205, 1012, 903, 852, 759 };
    // play the tone corresponding to the note name

    for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
    playTone(tones[i], duration);
    }
    }
    }
    void setup() {
    pinMode(speakerPin, OUTPUT);
    }
    void loop() {
    for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
    delay(beats[i] * tempo); // rest
    }
    else {
    playNote(notes[i], beats[i] * tempo);
    // pause between notes

      if (notes[i + 1] != 'n') {
        delay(tempo );
      }
      else {
        i += 2;
      }
    }
    

    }
    }

  • Piezo "happy birthday" 10 months ago

    Try this, I changed it a bit so you should be able to add a “n” between the notes that you want without a rest in between and a “0” between the beats.

    int speakerPin = 9;
    int length = 26; // the number of notes
    char notes[] = "aabacdaabaecaahfcndbggfcec "; // a space represents a rest
    int beats[] = {2,2,4,4,4,8,2,2,4,4,4,8,2,2,4,4,4,4,0,4,3,1,4,4,4,8,16 };
    int tempo = 75;

    void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
    }
    }
    void playNote(char note, int duration) {
    char names[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
    int tones[] = { 1515, 1351, 1136, 1205, 1012, 903, 852, 759 };
    // play the tone corresponding to the note name
    for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
    playTone(tones[i], duration);
    }
    }
    }
    void setup() {
    pinMode(speakerPin, OUTPUT);
    }
    void loop() {
    for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
    delay(beats[i] * tempo); // rest
    }
    else {
    playNote(notes[i], beats[i] * tempo);
    // pause between notes

    if notes[i+1] != “n”{
    delay(tempo );
    }
    else {
    i += 1;
    }
    }
    }
    }

  • Arduino 101 Clothes Recommender about 1 year ago

    This project uses the grove rgb lcd library so for this code (without alteration) you would need an i2c rgb lcd (preferably the one from grove). However, you could use any screen with a slight alteration to all of the lcd.____ lines.

Add projectSign up / Login