booyaa dot org
  • Adverts

  • 123-reg sucks!

    123-reg screwed up the renewal of my domain (booyaa.org). To read all about it click here

  • Link Exchange

    Allotment Vegetable Growing Allotment diaries, photographs, advice about growing vegetables, fruits and herbs with a forum for chatting on the plot.
  • Meta

  • « Arduino: i can haz knight riders! | Home | Web links for January 29th »

    Arduino: 4 button piezo synth (failed)

    By booyaa | January 29, 2008

    I had to give up on this project, I could get the LEDs to light up, but the most I could get out of the piezo speaker was faint clicks… :( The piezo was working cause this bit of code worked when it was just rigged up to power and the output pin.

    
    /*
    Author: booyaa (booyaa.org)
    Changelog
    20080128 - tidied up code to prep for noise making!
    */
    
    int speakerOut = 9;
    int val = 0;
    int i = 0; // was 4
    int maxInputs = 7;
    
    int buttons[] = { 4, 5 ,6, 7 };
    
    int tones[] = { 3830, 3400, 3038, 2864 };
    int count = 0;
    
    void setup() {
      for( i=4; i<=maxInputs; i++) {
        pinMode( i, INPUT );
      }
    
      pinMode(speakerOut, OUTPUT);
    
      Serial.begin( 9600 );
    }
    
    void loop() {
      for( i=4; i<=maxInputs; i++) {
        val = digitalRead( i );
    
        for ( count=4; count <= maxInputs; count++ ) {
          if ( val == 0 && i == count ) {
            Serial.print( "button = " );
            Serial.print( i );
            Serial.print( " val = " );
            Serial.print( val );
            Serial.print( " count = " );
            Serial.println( count );
    
            // this is where the music code will go, which comes from this sketch
            // http://www.arduino.cc/en/Tutotial/KeyboardSerial
            digitalWrite(speakerOut, HIGH);
            delayMicroseconds(tones[count]);
            digitalWrite(speakerOut, LOW);
            delayMicroseconds(tones[count]);
          }
    
        }
      }
      delay (500);
    }
    
    

    Topics: Uncategorized |

    Comments

    Subscribe without commenting