My goal is to make sure when I press a button it lights an LED, and when I press another button it plays a sound.
I keep getting the error:
exit status 1
could not convert 'digitalWrite(((uint8_t)((int)ledPins[index])), 1)' from 'void' to 'bool'
Here's my code:
const int button1Pin = 3; // pushbutton 1 pin - LEDs
const int ledPins[] = {10, 11, 12, 13}; // LED pins
int button1State = 0;
int index = 0;
const int button2Pin = 4; // pushbutton 2 pin - Sound
const int soundPin = 7; // sound pin
const int songLength = 18; // number of notes played
char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
int button2State = 0;
// Beats is an array values for each note and rest.
// A "1" represents a quarter-note, 2 a half-note, etc.
// Don't forget that the rests (spaces) need a length as well.
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
// The tempo is how fast to play the song.
// To make the song play faster, decrease this value.
int tempo = 150;
void setup() {
/* START LED PIN */
// Set up the pushbutton pins to be an input:
pinMode(button1Pin, INPUT); // LED button input
for(index = 0; index <= 3; index++) // foor loop that runs through the array "ledPins" one at a time until the final LED has been turned on.
{
pinMode(ledPins[index],OUTPUT);
// ledPins[index] is replaced by the value in the array.
// For example, ledPins[0] is 10
// For example, ledPins[1] is 11
// For example, ledPins[2] is 12
// For example, ledPins[3] is 13
}
button1State = digitalRead(button1Pin); // LED button state
/* END LED PIN */
/* START SOUND PIN */
pinMode(button1Pin, INPUT); // LED button input
pinMode(soundPin, OUTPUT); // sound button output
// note frequency
// c 262 Hz
// d 294 Hz
// e 330 Hz
// f 349 Hz
// g 392 Hz
// a 440 Hz
// b 494 Hz
// C 523 Hz
button2State = digitalRead(button2Pin); // sound button state
/* END SOUND PIN */
}
void oneAfterAnotherLEDLightUp()
{
int delayTime = 100; // time (milliseconds) to pause between LEDs
// make this smaller for faster switching
// turn all the LEDs on:
digitalWrite(ledPins[0], HIGH); //Turns on LED #0 (pin 2)
delay(delayTime); //wait delayTime milliseconds
digitalWrite(ledPins[1], HIGH); //Turns on LED #1 (pin 3)
delay(delayTime); //wait delayTime milliseconds
digitalWrite(ledPins[2], HIGH); //Turns on LED #2 (pin 4)
delay(delayTime); //wait delayTime milliseconds
digitalWrite(ledPins[3], HIGH); //Turns on LED #3 (pin 5)
delay(delayTime); //wait delayTime milliseconds
// turn all the LEDs off:
digitalWrite(ledPins[3], LOW); //Turn off LED #3 (pin 5)
delay(delayTime); //wait delayTime milliseconds
digitalWrite(ledPins[2], LOW); //Turn off LED #2 (pin 4)
delay(delayTime); //wait delayTime milliseconds
digitalWrite(ledPins[1], LOW); //Turn off LED #1 (pin 3)
delay(delayTime); //wait delayTime milliseconds
digitalWrite(ledPins[0], LOW); //Turn off LED #0 (pin 2)
delay(delayTime); //wait delayTime milliseconds
}
void soundButton() {
int i, duration;
for (i = 0; i < songLength; i++) // step through the song arrays
{
duration = beats[i] * tempo; // length of note/rest in ms
if (notes[i] == ' ') // is this a rest?
{
delay(duration); // then pause for a moment
}
else // otherwise, play the note
{
tone(soundPin, frequency(notes[i]), duration);
delay(duration); // wait for tone to finish
}
delay(tempo/10); // brief pause between notes
}
}
int frequency(char note)
{
// This function takes a note character (a-g), and returns the
// corresponding frequency in Hz for the tone() function.
int i;
const int numNotes = 8; // number of notes we're storing
// The following arrays hold the note characters and their
// corresponding frequencies. The last "C" note is uppercase
// to separate it from the first lowercase "c". If you want to
// add more notes, you'll need to use unique characters.
// For the "char" (character) type, we put single characters
// in single quotes.
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
// Now we'll search through the letters in the array, and if
// we find it, we'll return the frequency for that note.
for (i = 0; i < numNotes; i++) // Step through the notes
{
if (names[i] == note) // Is this the one?
{
return(frequencies[i]); // Yes! Return the frequency
}
}
return(0); // We looked through everything and didn't find it,
// but we still need to return a value, so return 0.
}
void loop() {
if ( ((button1State == LOW)) && ((button2State == LOW)) );
for(index = 0; index <= 3; index++)
{ digitalWrite(ledPins[index], HIGH) && digitalWrite(soundPin, HIGH) };
else if
((button1State == LOW)) // LED boolean value
for(index = 0; index <= 3; index++)
{ digitalWrite(ledPins[index], HIGH); }
else if
((button2State == LOW)) // sound boolean value
digitalWrite(soundPin, HIGH); // turn the sound on
else
for(index = 0; index <= 3; index++)
{ digitalWrite(ledPins[index], LOW) && digitalWrite(soundPin, LOW) };
}