Hi
Yes sorry that isn't everything. Here's everything, I have tried to put in some kind of flag to have the buzzer only buzz once and LED to remain on.
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPinR = A0; // Analog input pin that the potentiometer is attached to
const int analogInPinG = A1; // Analog input pin that the potentiometer is attached to
const int analogInPinB = A2; // Analog input pin that the potentiometer is attached to
int sensorValueR = 0; // value read from the pot
int sensorValueG = 0; // value read from the pot
int sensorValueB = 0; // value read from the pot
int outputValueR = 0; // value output to the PWM (analog out)
int outputValueG = 0; // value output to the PWM (analog out)
int outputValueB = 0; // value output to the PWM (analog out)
int outputR = 10;
int outputG = 11;
int outputB = 12;
int flagR = 1;
int countR = 0;
int toneR = 0;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(outputR, OUTPUT);
pinMode(outputG, OUTPUT);
pinMode(outputB, OUTPUT);
}
void loop() {
// read the analog in value:
sensorValueR = analogRead(analogInPinR);
sensorValueG = analogRead(analogInPinG);
sensorValueB = analogRead(analogInPinB);
// map it to the range of the analog out:
outputValueR = map(sensorValueR, 0, 1023, 0, 255);
outputValueG = map(sensorValueG, 0, 1023, 0, 255);
outputValueB = map(sensorValueB, 0, 1023, 0, 255);
if (outputValueR == 0 && flagR == 1) { //if red is pressed and tone red gone flag is up
digitalWrite(outputR, HIGH); //trun on read
flagR = 0; // reset flag R to off
toneR = 1; // set tone falg on
}
else{
digitalWrite(outputR, LOW);
}
if(toneR ==1){ // make a tone for a set amount of time
//Red tone 1
// play a note on pin 6 for 200 ms:
if(countR <= 1000){ //if Red counter is below 1000
tone(6, 220); // play tone
}
else{ // else if red counter is above 1000
noTone(6); //stop tone
countR = 0; // and reset the Red counter to off
}
countR++; // increment read counter
}
if (outputValueG == 0) {
digitalWrite(outputG, HIGH);
}
else {
digitalWrite(outputG, LOW);
}
if (outputValueB == 0) {
digitalWrite(outputB, HIGH);
}
else {
digitalWrite(outputB, LOW);
}
// change the analog out value:
// analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensorR = " );
Serial.print(sensorValueR);
Serial.print("\t outputR = ");
Serial.print(outputValueR);
Serial.print("\t sensorG = " );
Serial.print(sensorValueG);
Serial.print("\t outputG = ");
Serial.print(outputValueG);
Serial.print("\t sensorB = " );
Serial.print(sensorValueB);
Serial.print("\t outputB = ");
Serial.println(outputValueB);
}
Although it compiled ok, it still either doesn't stop the buzzer or it doesn't work at all along with the LED.
Many Thanks for you help