I basically have a bread board with an rgb led and a peizo buzzer with a photocell.
I have the codes for both. If I put a code for the rgb, it works. If I put the code for the peizo, it works. Once I paste both codes onto it it says there's an error because "void setup" and "void loop" are already defined. What do I do to get both things to work?
rgb led code:
/*
Adafruit Arduino - Lesson 7. RGB Fader
*/
int redLEDPin = 11;
int greenLEDPin = 10;
int blueLEDPin = 9;
int redSwitchPin = 7;
int greenSwitchPin = 6;
int blueSwitchPin = 5;
int red = 0;
int blue = 0;
int green = 0;
void setup()
{
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
pinMode(redSwitchPin, INPUT_PULLUP);
pinMode(greenSwitchPin, INPUT_PULLUP);
pinMode(blueSwitchPin, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(redSwitchPin) == LOW)
{
red ++;
if (red > 255) red = 0;
}
if (digitalRead(greenSwitchPin) == LOW)
{
green ++;
if (green > 255) green = 0;
}
if (digitalRead(blueSwitchPin) == LOW)
{
blue ++;
if (blue > 255) blue = 0;
}
analogWrite(redLEDPin, red);
analogWrite(greenLEDPin, green);
analogWrite(blueLEDPin, blue);
delay(10);
}
peizo code:
int speakerPin = 12;
int photocellPin = 0;
void setup()
{
}
void loop()
{
int reading = analogRead(photocellPin);
int pitch = 200 + reading / 4;
tone(speakerPin, pitch);
}
setup()
block and only oneloop()
block .... you have to merge the code from each pair of the blocks into one block