Nibbles and Bits
The Care and Feeding of My Pet Arduino


by Budd Churchward - WB7FHC - NIBBLES AND BITS LIBRARY


Teaching Arduino to Copy Morse Code

« 1 2  3  4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 »

Section 3
Now we will add a couple of lines to the sketch to make sure our Arduino is talking to the Serial Monitor on your computer.

Copy the three highlighted sections on the right and and paste them into your sketch in the places shown. Compile and run the code.

Open the Serial Monitor on your computer screen. You should see a lot of activity on the monitor as you press and release the key. In the next step we will clean that up a bit.

Next Section »


int myKey=14;    // We are borrowing Analog Pin 0 and using it as digital
int speaker=11;  // Speaker will be hooked between pin 11 and ground

int val=0;       // A value for key up and down
int myTone=440;  // Freq. of our tone

void setup() {
  pinMode(myKey, INPUT);
  pinMode(speaker,OUTPUT);

  // initialize the serial communication:
  Serial.begin(9600);

}



 void loop() {
   val=digitalRead(myKey);
   if (val) keyIsDown();
   if (!val) keyIsUp();
 }
 
void keyIsDown() {
  tone(speaker,myTone);
    Serial.print ('X');
}

void keyIsUp() {
  noTone(speaker);
    Serial.println();

}