User Tools

Site Tools


snd_serialread_arduino

Warning: Use of undefined constant PREG_PATTERN_VALID_LANGUAGE - assumed 'PREG_PATTERN_VALID_LANGUAGE' (this will throw an Error in a future version of PHP) in /var/www/kucjica/emperors-wiki/inc/parser/xhtml.php on line 633

Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /var/www/kucjica/emperors-wiki/inc/parser/xhtml.php on line 633

SND serial read > arduino

//create a simple melody 
//this melody will play first when you upload the code
// notes in the melody (defined in pitches.h)
int melody[] = {
  24, 32,32, 165, 220,0, 440, 180};
 
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };
  
  int incomingByte = 0; // incoming serial data
  int duration = 0;
  int snd = 8; // speaker pin
 
void setup() {
  // iterate over the notes of the melody:
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  //pinMode(snd, OUTPUT);
  for (int thisNote = 0; thisNote < 8; thisNote++) {
 
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);
 
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }
}
 
void loop() {
  
    // send data only when you receive data:
    if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    
  tone(snd, incomingByte,100);
    }
}
snd_serialread_arduino.txt · Last modified: 2014/01/23 12:37 by zoza