6 Replies Latest reply on Sep 17, 2018 8:24 AM by richipearl

    Please help me to debug this programme

    richipearl

      I wrote the following code to make a seven digit segment display number from 1 to 9 continuously but while compiling the arduino ide write error, too many argument  to function turnOn

       

       

      byte ledPin[7]={2,3,4,5,6,8,9};

      #define buttonPin 11

      int no = 0;

      int pushButton = 0;

      void setup() {

        for(int a = 0;a < 7;a++){

        pinMode(ledPin[a],OUTPUT);

        }

        pinMode(buttonPin,INPUT_PULLUP);

        turnOn();

      }

        // put your setup code here, to run once:

       

      void turnOn()

        pushButton = digitalRead(buttonPin);

       

        {

          if (pushButton == LOW)

          no++;

          delay(200);

        }

      {

      switch(no)

        {

          case 1:

            digitalWrite(ledPin[0],LOW);

            digitalWrite(ledPin[1],HIGH);

            digitalWrite(ledPin[2],HIGH);

            digitalWrite(ledPin[3],LOW);

            digitalWrite(ledPin[4],LOW);

            digitalWrite(ledPin[5],LOW);

            digitalWrite(ledPin[6],LOW);

            break;

          case 2:

           digitalWrite(ledPin[0],HIGH);

           digitalWrite(ledPin[1],LOW);

           digitalWrite(ledPin[2],HIGH);

           digitalWrite(ledPin[3],HIGH);

           digitalWrite(ledPin[4],HIGH);

           digitalWrite(ledPin[5],HIGH);

           digitalWrite(ledPin[6],LOW);

           break;

          case 3:

            digitalWrite(ledPin[0],HIGH);

            digitalWrite(ledPin[1],HIGH);

            digitalWrite(ledPin[2],HIGH);

            digitalWrite(ledPin[3],HIGH);

            digitalWrite(ledPin[4],LOW);

            digitalWrite(ledPin[5],HIGH);

            digitalWrite(ledPin[6],LOW);

            break;

          case 4:

          digitalWrite(ledPin[0],LOW);

          digitalWrite(ledPin[1],HIGH);

          digitalWrite(ledPin[2],HIGH);

          digitalWrite(ledPin[3],LOW);

          digitalWrite(ledPin[4],LOW);

          digitalWrite(ledPin[5],HIGH);

          digitalWrite(ledPin[6],HIGH);

          break;

         case 5:

         digitalWrite(ledPin[0],HIGH);

         digitalWrite(ledPin[1],HIGH);

         digitalWrite(ledPin[2],LOW);

         digitalWrite(ledPin[3],HIGH);

         digitalWrite(ledPin[4],LOW);

         digitalWrite(ledPin[5],HIGH);

         digitalWrite(ledPin[6],LOW);

         break;

        case 6:

          digitalWrite(ledPin[0],HIGH);

          digitalWrite(ledPin[1],HIGH);

          digitalWrite(ledPin[2],LOW);

          digitalWrite(ledPin[3],HIGH);

          digitalWrite(ledPin[4],HIGH);

          digitalWrite(ledPin[5],HIGH);

          digitalWrite(ledPin[6],HIGH);

          break;

        case 7:

          digitalWrite(ledPin[0],HIGH);

          digitalWrite(ledPin[1],HIGH);

          digitalWrite(ledPin[2],HIGH);

          digitalWrite(ledPin[3],LOW);

          digitalWrite(ledPin[4],LOW);

          digitalWrite(ledPin[5],LOW);

          digitalWrite(ledPin[6],LOW);

          break;

        case 8:

            digitalWrite(ledPin[0],HIGH);

            digitalWrite(ledPin[1],HIGH);

            digitalWrite(ledPin[2],HIGH);

            digitalWrite(ledPin[3],HIGH);

            digitalWrite(ledPin[4],HIGH);

            digitalWrite(ledPin[5],HIGH);

            digitalWrite(ledPin[6],HIGH);

            break;

        case 9:

          digitalWrite(ledPin[0],HIGH);

          digitalWrite(ledPin[1],HIGH);

          digitalWrite(ledPin[2],HIGH);

          digitalWrite(ledPin[3],HIGH);

          digitalWrite(ledPin[4],LOW);

          digitalWrite(ledPin[5],HIGH);

          digitalWrite(ledPin[6],HIGH);

          break;

          }

          }

      }

      void loop()

      {

        for (int b = 0;b < 10;b++)

        {

          turnOn(b);

          delay(500);   

        }

       

        }

       

       

      // put your main code here, to run repeated

        • Re: Please help me to debug this programme
          Jan Cumps

          your turnOn() function expects 0 parameters, but you pass it 1 parameter: turnOn(b)

          6 of 6 people found this helpful
            • Re: Please help me to debug this programme
              richipearl

              Thanks for your contribution but can you please explain more

                • Re: Please help me to debug this programme
                  Fred27

                  There's not a huge amount the explain. Only one line needs to change. turnOn(b); need to become turnOn();

                   

                  void loop()
                  {
                    for (int b = 0;b < 10;b++)
                    {
                      turnOn();
                      delay(500);   
                    }
                  }

                   

                  Of course, once it compiles then it may not do exactly what you were expecting. It's best to tackle this one step at a time and work through the bugs. That's the only way you'll get an understanding of what you're trying to do.

                  4 of 4 people found this helpful
                  • Re: Please help me to debug this programme
                    afmishaq

                    Rachel,

                     

                    You have defined your function as: void turnOn()

                     

                    The initial void says that it will not return anything which is fine because your function will just turn on  some LED segments and does not need to return any value.

                     

                    However, the empty brackets say that it does not any arguments. This is not correct because you need to pass a number to turn on the desired segments. So, you have to put something in the brackets to indicate tthat you will be passing an argument. In your case, you are passing an integer value, so you may write 'int b' there.

                     

                    Hope this helps,

                    Faiz

                    4 of 4 people found this helpful
                • Re: Please help me to debug this programme
                  beacon_dave

                  Looks like you have an opening brace in the wrong place as well:

                   

                  void turnOn()
                  {  
                    pushButton = digitalRead(buttonPin);
                    
                    {    
                      if (pushButton == LOW)
                      no++;
                      delay(200);
                    }

                   

                   

                  perhaps should be:

                   

                  void turnOn()
                  {  
                    pushButton = digitalRead(buttonPin);
                     
                    if (pushButton == LOW)
                    {
                      no++;
                      delay(200);
                    }
                  4 of 4 people found this helpful
                  • Re: Please help me to debug this programme
                    richipearl

                    Thanks so much to everyone's contribution

                    byte ledPin[7]={2,3,4,5,6,8,9};// declare pins to led

                    #define buttonPin 11 // set buttonpin

                    int no = 0;

                    int pushButton = 0;

                     

                     

                    void setup() {

                      for(int a = 0;a < 7;a++){

                      pinMode(ledPin[a],OUTPUT);

                      }               // set ledPin as output

                      pinMode(buttonPin,INPUT);  // set buttonPin to input

                      pinMode(buttonPin,INPUT_PULLUP);

                    }

                      // put your setup code here, to run once:

                      void loop()

                      {

                        turnOn();   // declare turnOn as function

                        if(no > 9)

                          no = 0; 

                       

                      }

                      void turnOn()

                      pushButton = digitalRead(buttonPin);// set the pushbutton to read into from the button

                      delay(500);

                        if (pushButton == LOW) // when buttonPress is detected display number

                        {

                        no++;

                    switch(no)

                      {

                        case 1:

                          digitalWrite(ledPin[0],LOW);

                          digitalWrite(ledPin[1],HIGH);

                          digitalWrite(ledPin[2],HIGH);

                          digitalWrite(ledPin[3],LOW);

                          digitalWrite(ledPin[4],LOW);

                          digitalWrite(ledPin[5],LOW);

                          digitalWrite(ledPin[6],LOW);

                          break;

                        case 2:

                         digitalWrite(ledPin[0],HIGH);

                         digitalWrite(ledPin[1],HIGH);

                         digitalWrite(ledPin[2],LOW);

                         digitalWrite(ledPin[3],HIGH);

                         digitalWrite(ledPin[4],HIGH);

                         digitalWrite(ledPin[5],LOW);

                         digitalWrite(ledPin[6],HIGH);

                         break;

                        case 3:

                          digitalWrite(ledPin[0],HIGH);

                          digitalWrite(ledPin[1],HIGH);

                          digitalWrite(ledPin[2],HIGH);

                          digitalWrite(ledPin[3],HIGH);

                          digitalWrite(ledPin[4],LOW);

                          digitalWrite(ledPin[5],LOW);

                          digitalWrite(ledPin[6],HIGH);

                          break;

                        case 4:

                        digitalWrite(ledPin[0],LOW);

                        digitalWrite(ledPin[1],HIGH);

                        digitalWrite(ledPin[2],HIGH);

                        digitalWrite(ledPin[3],LOW);

                        digitalWrite(ledPin[4],LOW);

                        digitalWrite(ledPin[5],HIGH);

                        digitalWrite(ledPin[6],HIGH);

                        break;

                       case 5:

                       digitalWrite(ledPin[0],HIGH);

                       digitalWrite(ledPin[1],LOW);

                       digitalWrite(ledPin[2],HIGH);

                       digitalWrite(ledPin[3],HIGH);

                       digitalWrite(ledPin[4],LOW);

                       digitalWrite(ledPin[5],HIGH);

                       digitalWrite(ledPin[6],HIGH);

                       break;

                      case 6:

                        digitalWrite(ledPin[0],HIGH);

                        digitalWrite(ledPin[1],LOW);

                        digitalWrite(ledPin[2],HIGH);

                        digitalWrite(ledPin[3],HIGH);

                        digitalWrite(ledPin[4],HIGH);

                        digitalWrite(ledPin[5],HIGH);

                        digitalWrite(ledPin[6],HIGH);

                        break;

                      case 7:

                        digitalWrite(ledPin[0],HIGH);

                        digitalWrite(ledPin[1],HIGH);

                        digitalWrite(ledPin[2],HIGH);

                        digitalWrite(ledPin[3],LOW);

                        digitalWrite(ledPin[4],LOW);

                        digitalWrite(ledPin[5],LOW);

                        digitalWrite(ledPin[6],LOW);

                        break;

                      case 8:

                          digitalWrite(ledPin[0],HIGH);

                          digitalWrite(ledPin[1],HIGH);

                          digitalWrite(ledPin[2],HIGH);

                          digitalWrite(ledPin[3],HIGH);

                          digitalWrite(ledPin[4],HIGH);

                          digitalWrite(ledPin[5],HIGH);

                          digitalWrite(ledPin[6],HIGH);

                          break;

                      case 9:

                        digitalWrite(ledPin[0],HIGH);

                        digitalWrite(ledPin[1],HIGH);

                        digitalWrite(ledPin[2],HIGH);

                        digitalWrite(ledPin[3],HIGH);

                        digitalWrite(ledPin[4],LOW);

                        digitalWrite(ledPin[5],HIGH);

                        digitalWrite(ledPin[6],HIGH);

                        break;

                        }

                        }

                    }

                    my code is now working