These errors keep occurring even when I try to change the code. (Actually sometimes more appear when I mess with it)
error: too few arguments to function 'void analogWrite(uint8_t, int)'
sketch_oct28a:28: error: at this point in file
sketch_oct28a:42: error: 'frequency' was not declared in this scope
sketch_oct28a:83: error: 'note' was not declared in this scope
sketch_oct28a:85: error: return-statement with a value, in function returning 'void'
My code is supposed to make a RGB LED, piezo, and motor interact with a potentiometer and button. Everything is supposed to be off until the button is pressed and held. Then, when button pressed, the RGB flashes colors (the delay is the potentiometer), the piezo does a scale, and the motor spins (how fast is based on the potentiometer too). Right now it won't even finish uploading to the arduino board. I took out all the RGB colors to make the code shorter for this.
const int RED_PIN = 11;
const int GREEN_PIN = 12;
const int BLUE_PIN =13;
int buzzerPin = 9;
int sensorPin = 0;
int motorPin = 10;
int buttonPin = 2;
const int songLength = 13;
char notes[] = "cdefgabagfedc";
int beats[] = {2,2,2,2,2,2,2,2,2,2,2,2,2};
int tempo = 150;
void setup()
{
pinMode(RED_PIN,OUTPUT);
pinMode(GREEN_PIN,OUTPUT);
pinMode(BLUE_PIN,OUTPUT);
pinMode(buzzerPin,OUTPUT);
pinMode(motorPin,OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop()
{
int buttonState;
int i, duration;
int sensorValue;
buttonState = digitalRead(buttonPin);
sensorValue = analogWrite(sensorPin);
Serial.print(sensorValue);
Serial.print(duration);
Serial.println();
if(sensorPin<50)
{
motorPin = 50;
}
for(i = 0; i < songLength; i++)
{
duration = beats[i]*tempo;
tone(buzzerPin, frequency(notes[i], duration);
delay(sensorValue);
}
int frequency(char note);
const int numNotes = 7;
char names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b'};
int frequencies[] = {262, 294, 330, 349, 392, 440, 494};
for (i = 0; i , numNotes; i++) {
if (names[i] == note)
{
return(frequencies[i]);
}
}
}