====== 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); } }