Help needed to convert some code.

I think I've got it, got a clean compile with this:

void CheckInputs(boolean screen = true);  //passes a true value to screen
                                            //and sets CheckInputs to perform
                                            //the initial input check.

boolean inputflag = false;                  //the initial input error check
boolean exitflag = false;
int x;
const int buttonPins[] = {2, 3, 4, 5, 6};

void setup()
{
    Serial.begin(9600);
}

void loop()
{
  
  CheckInputs();
  
  Serial.println("Initial Check Complete");
  Serial.println("Enter number of questions");
  x = Serial.read();
  
  for (int i = 0; i < x; i++)
  {
    do
    {
      CheckInputs(false);

      if (digitalRead(buttonPins[4]));
      {
        for (int a= 0; a <=4; a++)
          {
            digitalWrite(buttonPins[a], LOW);
          }
        inputflag = false;
        exitflag = true;
      } while (exitflag == false);
    }
    while (digitalRead(buttonPins[4]));

    exitflag = false;
    
    
    
  }
}

void CheckInputs(boolean screen)
{
  int i;
  for (i = 0; i <=4; i++)
  {
    boolean inputstatus = digitalRead(buttonPins[i]);
    
    if (inputstatus)
    {
      Serial.print("Input ");
        Serial.print(i+1); 
        Serial.println(" depressed");
      inputflag = true;
    }
    else
    {
      if (i != 4)
        if (!inputflag)
        {
          Serial.print("Contestant ");
            Serial.print(i+1);
            Serial.println(" buzzed!");
          inputflag = true;
        }
    }
  }
  
  if (!inputflag && screen)
  {
    Serial.println("No inputs depressed");
  }
  
}

Hopefully, this will work.

EDIT: Nope, it just keeps looping through the initial check saying all inputs are pressed. :frowning:

Nope, it just keeps looping through the initial check saying all inputs are pressed

Pull-ups?
Pull-downs?

Well, for the contestant buttons, I'm using some handsets scavenged from an interactive DVD quiz game. These have 5 buttons, each with a different value resistor in series with it. The original control box used the different voltage potentials to distinguish which button had been pressed on each handset.

The only button I could get the Arduino to pick up when I tested it was the one with the 1K resistor.

      if (digitalRead(buttonPins[4]))[glow];[/glow]

This isn't doing anything...

        exitflag = true;
      } while (exitflag == false);

Doesn't look like exitFlag will ever get to be false.

            digitalWrite(buttonPins[a], LOW);

Are the pins listed in buttonPins input or output? You are trying to use them as both.

You can't have it, with switches attached, both ways.

How are the switches wired?

Probably the simplest way is to use the AVR's internal pull-ups, but this inverts the logic of an open switch (It will be HIGH when open, and LOW when closed), but this is simple to deal with in software.

Without pull-ups or pull-downs, the pins are floating and can appear random.

Have a look at the examples and tutorials.

OK, I think that rather than try to shoehorn the old code into the Arduino, I'm going to have to rewrite this from scratch. stick with the code that works and use the K8055.

Thanks for all the help, but as the old adage goes, if it ain't broke, don't fix it.

I think that rather than try to shoehorn the old code into the Arduino

I don't know about the other guys here, but I'm glad I didn't invest too much time in your day.

I think that rather than try to shoehorn the old code into the Arduino

I don't know about the other guys here, but I'm glad I didn't invest too much time in your day.

I felt a bit annoyed that I'd spent my limited time on someone who gave up, when I might have helped someone who made some progress instead. But I know who I'll avoid helping in future, and ...

I'm now quite pleased that I have an example thread where a simple program was made so complex that it defeated the author who claimed they'd got it working on different hardware.

In future I can reference this thread, and say "Rather than start with that complex old thing, take confidence from it that you can do it again, but instead start with a simple program. You will make progress faster. You might learn something new. It may even turn out much better! Sadly, this person didn't do that, and ended up giving up!"

Many silver linings are embedded in clouds ;D

GB

gbulmer, had I a cap to doff, I would doff it at you!

I like your attitude - you are obviously far less cynical than I. ;D

AWOL - sorry I missed a bit and modified it.
I may have tarnished my attitude

GB

I'm now quite pleased that I have an example thread where a simple program was made so complex that it defeated the author who claimed they'd got it working on different hardware (even though they didn't seem to know the syntax of the C/C++ language).

OK, you know what? I couldn't care less if you don't believe I got it working on the old platform, I know that it works because it compiles and does what it was written to do. It's not my fault you don't have the board I originally wrote it for, or that for something that is much older than the Arduino technology-wise, the SDK for it appears to have far better and more user-friendly I/O handling capabilities.

So yeah, go ahead and mock the n00b and by all means, use me as an example of someone who apparently can't code. I'll stick with my working code, thank you very much.

I'm done here, if an admin could come along and delete my account and this thread please.

flapjack - I am sorry you feel so offended.

I may be judgmental, but IMHO reading code which can't possibly compile being presented as if it is okay, wastes our time. It only takes a couple of words to say "This doesn't compile".

IMHO it is unhelpful to post code which doesn't compile without warning the forum. I can't speak for anyone else, but I feel that it is ungracious. I feel that it is unappreciative of other peoples time and effort.

Worse, for me, folks who are less experienced may read such broken code, and believe it works. Then go on to try something similar and fail. They may be left feeling it is there fault that they can't get an example working. It may do harm to innocents.

HTH
GB

reading code which can't possibly compile

OK, so I had a few problems translating the code over to the Arduino environment, but just because you can't test the original code doesn't mean it was shoddy enough to poke holes in it.

I'll tell you what, it was written and compiled using Bloodshed Dev-C++, so it was compiled using gcc, essentially the same compiler as the Arduino environment compiles with.

You know, it took me ages to hack out that original code and the sense of accomplishment I felt when I finally got it to do what I wanted it to do was destroyed in mere minutes on here. You had an excellent opportunity to help a newcomer to the Arduino platform embrace it, but instead you all decided that you'd rather just sit there poking holes in my code.

I think it's not my coding skills that need more polishing as much as your ability to render effective assistance.

EDIT: Anyway, as I said, I'm done with this place. Lock the thread, delete my account and I'll move on somewhere else.

You know what - I spotted the extraneous "else;"s and the redundant "return;" in the original post.
I spotted the redundant code and the naive coding style.
I kept quiet about it.
I didn't want to embarrass the poster.

I tried to find out what the OP wanted to do, and tried to probe his/her level of expertise.
I tried to hint and nudge in the right direction, rather than (here comes that word again) embarrass the poster with actually writing the code for him/her.

I needn't have bothered.
Thanks a bunch.

Groove - I apologise.
I admire your tolerance, helpfulness and strategy.
I think I understand.
I should have simply stopped trying to help.

Thanks for the help.

My fault.
GB