I have this code, which runs once when the button is pressed;
if (digitalRead(A0)) {
int melody[] = {
NOTE_D3, NOTE_DS3,
//set the notes u want , !
};
int LooongthS[] = {
4, 4, 4, 4, 4, 4, 4
};
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 7; thisNote++) {
int Looongth = 1000 / LooongthS[thisNote];
tone(8, melody[thisNote], Looongth);
int pauseBetweenNotes = Looongth * 1.30;
delay(pauseBetweenNotes);
noTone(8);
}
for (int i = 0; i <= 4; i++) {
//Goes Four times
int redVal = 255;
int blueVal = 0;
int greenVal = 0;
for ( int i = 0 ; i < 255 ; i += 1 ) {
greenVal += 1;
redVal -= 1;
analogWrite( GREEN, 255 - greenVal );
analogWrite( RED, 255 - redVal );
delay( delayTime );
}
redVal = 0;
blueVal = 0;
greenVal = 255;
for ( int i = 0 ; i < 255 ; i += 1 ) {
blueVal += 1;
greenVal -= 1;
analogWrite( BLUE, 255 - blueVal );
analogWrite( GREEN, 255 - greenVal );
delay( delayTime );
}
redVal = 0;
blueVal = 255;
greenVal = 0;
for ( int i = 0 ; i < 255 ; i += 1 ) {
redVal += 1;
blueVal -= 1;
analogWrite( RED, 255 - redVal );
analogWrite( BLUE, 255 - blueVal );
delay( delayTime );
}
I would like it that when the button is pressed, it keeps on repeating, until the button is pressed again.
i.e. the button should act like a swithc
could you please help correct the code, any help would be appreciated.
Thank you