//button to control the pitch
const int pitchControl = 5;
int pitchState = 0;
int toner;
int startPitch = 100;
//onOff button
const int onOff = 8;
int button;
int oldButton = 0;
int onOffState = 0;
const int led = 4;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println( "The sketch has started");
pinMode(pitchControl, INPUT);
pinMode(onOff, INPUT);
pinMode(led, OUTPUT);
// Testing the piezo
for( int i=100; i<16000; i+=(i/10))
{
tone( 2, i);
delay( 50);
}
noTone( 2);
// Testing the led
for( int i=0; i<10; i++)
{
digitalWrite( led, HIGH);
delay( 200);
digitalWrite( led, LOW);
delay( 200);
}
}
void loop() {
button = digitalRead(onOff); // read the state of the onOff Button
// if the button is high and the old button is low
if (button && !oldButton)
{
// we have a new button press
if (onOffState == 0) //if the state is off, turn it on
{
// turn the LED on and start the Piezo
digitalWrite(led, HIGH);
tone(2, startPitch);
onOffState = 1;
}
else // if the state is on, turn things off
{
digitalWrite(led, LOW);
noTone(2);
onOffState = 0;
}
oldButton = 1;
}
// if button is low and old button is high
else if (!button && oldButton)
{
// the button was released
oldButton=0;
}
delay(20);
}
// WHERE DO YOU GO YOU SILLY PIECE OF CODE!!!!!!!!!
//pitchState = digitalRead(pitchControl);
//
// if (pitchState == LOW)
// {
// startPitch = startPitch + 300;
// Serial.print("Start Pitch: ");
// Serial.println(startPitch);
// tone(2, startPitch);
// }