Go Down

Topic: Run Void *** when button is pressed (Read 1 time) previous topic - next topic

PMKimpton


Quote
They are called "void pong" and "void pattern"

No, they are called "pong" and "pattern".
"void" describes the return type of the function.


Thanks, Yes I understand that, I just typed it to help get my issue across.

PeterH


Im not a coder, I find this really hard to get my head round. Thanks everyone for the help and advice.


There is rather a lot of code there and, given that you are 'not a coder' and presumably didn't write this code, you have set yourself a difficult task to change how these two games work.

I suggest you write a much simpler sketch that just reads the input and switches between two modes that do something simple, such as printing "I'm running game 1" and "I'm running game 2" so that you can solve this part of the problem in isolation before you try to adopt that solution into the full sketch.
I only provide help via the forum - please do not contact me for private consultancy.

PMKimpton

#7
Dec 17, 2012, 05:45 pm Last Edit: Dec 17, 2012, 05:49 pm by PMKimpton Reason: 1
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:
Code: [Select]

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,
Code: [Select]


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.

Arrch

This seems to be one of those Give me the code for it to do what I want, I don't want to actually how to code type of posts.

PMKimpton

#9
Dec 17, 2012, 06:45 pm Last Edit: Dec 17, 2012, 06:47 pm by PMKimpton Reason: 1

This seems to be one of those Give me the code for it to do what I want, I don't want to actually how to code type of posts.


In some ways it may appear like that. I've been working on this project for 8 weeks and have built a fine matrix with over 620 led's, had to learn to solder correctly, design circuit boards after learning the software to do that, had to learn about transistors, IC's, power management, resistors, diodes, you name it. I'm studying as fast as I can and have come a long way in those 8 weeks.

My back is against the way, I have to get this finished in the next day or two as it's a CHRISTMAS DISPLAY and a present for someone. There's no point in me finishing it in February.

I have managed to learn everything I can in these past weeks and this is the first time I've honestly needed some help.

I understand the reasons for "guiding" people and helping them to learn, and I will, but as for this project.......  I NEED HELP TODAY

Go Up