and using now using the Serial and not the SoftwareSerial
#include <stdlib.h>
#include <SoftwareSerial.h>
int speakerPin = 9;
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};
// mid C C# D D# E F F# G G# A
int income = 0;
void setup()
{
Serial.begin(9600);
while (! Serial); // Wait untilSerial is ready - Leonardo
}
void loop()
{
recieveInputPassword();
}
void recieveInputPassword()
{
if (Serial.available() > 8)
{
for(int i = 0; i < 8; i++)
{
income = Serial.read();
//mySerial.print("I received: ");
Serial.println(income, DEC);
if(income == 52)
{
giveSignal();
}
}
Serial.println("SPACE");
}
}
void giveSignal()
{
int i;
for(i = 0; i<3; i++)
{
tone(speakerPin, tones[0]);
delay(1000);
noTone(speakerPin);
}
}
output
0
0
0
0
0
0
0
0
SPACE
0
252
0
0
0
0
0
0
SPACE
0
0
0
0
0
0
0
0
SPACE
0
0
0
0
0
0
0
0
SPACE
0
0
0
0
0
0
0
0
SPACE
all 3 times the output can go on forever