Go Down

Topic: to many arguments to function (Read 1 time) previous topic - next topic

arduinohabib

Hi all! I was writing some Arduino seven seg code, and it wouldn't compile, even though there was nothing wrong with the code.
Code: [Select]
void sevenseg(int val){
 switch(val){
   case'0': zero();
   break;
   case'1': one();
   break;
   case'2': two();
   break;
   case'3': three();
   break;
   case'4': four();
   break;
   case'5': five();
   break;
   case'6': six();
   break;
   case'7': seven();
   break;
   case'8': eight();
   break;
   case'9': nine();
   break;
 }
}

the error message:
Quote

/sevenseg.h: In function 'void setup()':
sevenseg.h:262: error: too many arguments to function 'void sevenseg(int)'
sketch_jan29a:13: error: at this point in file

Can anyone please tell me what the problem is?
Thanks
Habib
What is man's best friend? The breadboard!

PaulS

Quote
Can anyone please tell me what the problem is?

Sure. The function expects one argument. You are calling it with more than one. Don't do that.

AWOL

Quote
Can anyone please tell me what the problem is?

The problem is you didn't show us the code (there's a big clue here - "In function 'void setup()': ")
And what PaulS said.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

arduinohabib

All right, this is the full code:
Code: [Select]
#include"sevenseg.h"
int val=0;
void setup(){
  sevensegpins(13, 12, 11, 10, 9, 8, 7);
  common_cathode(true);
}
void loop(){
  val=(analogRead(0));
  val=map(val, 0, 1023, 0, 9);
  sevenseg(val);
}

and also
Code: [Select]
#include<Arduino.h>
int pin_a;
int pin_b;
int pin_c;
int pin_d;
int pin_e;
int pin_f;
int pin_g;
int ON;
int OFF;
void sevensegpins(int a, int b, int c, int d, int e, int f, int g){
  pin_a=a;
  pin_b=b;
  pin_c=c;
  pin_d=d;
  pin_e=e;
  pin_f=f;
  pin_g=g;
  pinMode(pin_a, OUTPUT);
  pinMode(pin_b, OUTPUT);
  pinMode(pin_c, OUTPUT);
  pinMode(pin_d, OUTPUT);
  pinMode(pin_e, OUTPUT);
  pinMode(pin_f, OUTPUT);
  pinMode(pin_g, OUTPUT);
}
void common_cathode(boolean cathode){
  if(cathode==true){
    ON=HIGH;
    OFF=LOW;
  }
  else{
    ON=LOW;
    OFF=HIGH;
  }
}
void clearall(){
  digitalWrite(pin_a, OFF);
  digitalWrite(pin_b, OFF);
  digitalWrite(pin_c, OFF);
  digitalWrite(pin_d, OFF);
  digitalWrite(pin_e, OFF);
  digitalWrite(pin_f, OFF);
  digitalWrite(pin_g, OFF);
}
void zero(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void one(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void two(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_d, ON);
}
void three(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void four(){
  clearall();
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void five(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void six(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void seven(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void eight(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void nine(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void lettera(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterb(){
  clearall();
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_g, ON);
}
void letterB(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterc(){
  clearall();
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_g, ON);
}
void letterC(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void letterd(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_g, ON);
}
void letterD(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void lettere(){
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterE(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterf(){ 
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_g, ON);
  }
void letterh(){
  clearall();
  digitalWrite(pin_c, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterH(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void letterl(){
  clearall();
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void letterL(){
  clearall();
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_d, ON);
}
void letterp(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterq(){
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letters(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void letteru(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void sevenseg(int val){
  switch(val){
    case'0': zero();
    break;
    case'1': one();
    break;
    case'2': two();
    break;
    case'3': three();
    break;
    case'4': four();
    break;
    case'5': five();
    break;
    case'6': six();
    break;
    case'7': seven();
    break;
    case'8': eight();
    break;
    case'9': nine();
    break;
  }
}
What is man's best friend? The breadboard!

arduinohabib

What is man's best friend? The breadboard!

billroy

#5
Jan 29, 2013, 04:12 pm Last Edit: Jan 29, 2013, 04:14 pm by billroy Reason: 1
I don't know if this is your bug or not, but attempting to reassign a system-provided define like ON or OFF like this is creative but not going to work:
Code: [Select]

void common_cathode(boolean cathode){
 if(cathode==true){
   ON=HIGH;
   OFF=LOW;
 }
 else{
   ON=LOW;
   OFF=HIGH;
 }
}


-br

Edit: Never mind.  I was mistaken in assuming the ON and OFF were system defines.  My bad.

AWOL

I'd suggest the code you posted is not the code you're trying to compile.
Here's the error message I got:
Quote
Binary sketch size: 2436 bytes (of a 14336 byte maximum)


(compiled for 168 on IDE 1.0)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

AWOL

Quote
but attempting to reassign a system-provided define like ON or OFF like this is creative but not going to work:

Why not?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

billroy

I had myself confused that ON was a #define.  More coffee...

-br

HazardsMind

You dont need to have,
Quote
digitalWrite(pin_a, OFF);
 digitalWrite(pin_b, OFF);
 digitalWrite(pin_c, OFF);
 digitalWrite(pin_d, OFF);
 digitalWrite(pin_e, OFF);
 digitalWrite(pin_f, OFF);
 digitalWrite(pin_g, OFF);
there is an easier way to get your LEDs to light up, but if it compiles like that and thats what you want to use, then go for it.

Alternative:
just use an array,
0b00000000 = all off
0b00101010  = something on
0b00010101 = something else on
.
.
0b11111111 = all on
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

arduinohabib

Hey all this code compiled in IDE 1.0 but did not compile in Arduino ERW. I was using ERW...Sorry for the time.
What is man's best friend? The breadboard!

arduinohabib

@HazerdousMind Thank you I knew that but this was old code I was going through, copy and pasting it
Thanks anyway!
Habib
What is man's best friend? The breadboard!

AWOL

Code: [Select]
val=map(val, 0, 1023, 0, 9);
 sevenseg(val);


Code: [Select]
void sevenseg(int val){
 switch(val){
   case'0': zero();
   break;
   case'1': one();
   break;
   case'2': two();


Your code will not work - lose the quotes.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

arduinohabib

I know... But why not? It used to.
What is man's best friend? The breadboard!

KeithRB

'0' is ASCII character 0, not the integer 0. ASCII character 0 is actually decimal 48.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview