In fact this code is made from two other scripts. I have cut and pasted bits to try and get it working without really understanding whats going on.
I agree with your suggestion. I had started already. I setup a breadboard with a button and led and got the code to switch the led on/off. This works well. What I would need from this is to learn how to change the command from ledPin command to running void pattern() or void pong()
heres the button code:
int switchPin = 7;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;
void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}
void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledOn = !ledOn;
}
lastButton = currentButton;
digitalWrite(ledPin, ledOn);
}
Say I wanted to have this in the button code above,
void flashslow() {
digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(ledPin, LOW);
delay(2000);
}
void flashfast() {
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
}
Instead of the button code turning on/off the led, how would i get it to switch between the two codes above? If I could figure this out Im sure I can get my pong code working.