Basic function declaration question

OK, so I'm beginning to work with custom functions and I really thought I had a handle on it. Wrote a couple for the last sketch with minimal trouble. I've been scrutinizing the difference between the functions in the previous (and related) sketch and the current(see below). Banged my head against the wall for a while now....can't figure out what I've done for the life of me. Thanks for your help!

I've highlighted the functions in question by bold/underline.

==================
DEBUGGER

Error message from debugger:

Arduino: 1.8.7 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users....\Documents\Arduino\7seg_2switches\7seg_digit_func\7seg_digit_func.ino: In function 'void loop()':

7seg_digit_func:61:16: error: 'disp_1' was not declared in this scope

disp_1(a, f);

^

7seg_digit_func:64:25: error: 'disp_2' was not declared in this scope

disp_2(a, b, d, g, h);

^

C:\Users,,,,,\Documents\Arduino\7seg_2switches\7seg_digit_func\7seg_digit_func.ino: In function 'void slowBlink(int, int)':

7seg_digit_func:80:29: error: a function-definition is not allowed here before '{' token

void disp_1(int a, int f) {

^

7seg_digit_func:91:50: error: a function-definition is not allowed here before '{' token

void disp_2(int a, int b, int d, int g, int h){

^

7seg_digit_func:103:3: error: expected '}' at end of input

}

^

exit status 1
'disp_1' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

==================
SKETCH

// Enable all 7-seg display to output
int a = 4; pinMode(a, OUTPUT);
int b = 5; pinMode(b, OUTPUT);
int c = 6; pinMode(c, OUTPUT);
int d = 7; pinMode(d, OUTPUT);
int e = 8; pinMode(e, OUTPUT);
int f = 9; pinMode(f, OUTPUT);
int g = 10; pinMode(g, OUTPUT);
int h = 11; pinMode(h, OUTPUT);

const int lhInput = 2;
const int rhInput = 1;

// RH switch input
pinMode(rhInput, INPUT);
// LH switch input
pinMode(lhInput, INPUT);
}

void loop() {

// Designate all 7seg terminals by alphabet (pursuant to diagram in journal)
int a = 4;
int b = 5;
int c = 6;
int d = 7;
int e = 8;
int f = 9;
int g = 10;
int h = 11;
// Define input pins
const int lhInput = 2;
const int rhInput = 1;
// Designate output pins
const int decimal = e;
// switch-state variables, initialized to false (no button presses)
boolean lhState = LOW;
boolean rhState = LOW;
// delay to give the feel of a loop reset
delay(2000);
// delay and # of LED pulses
int delayPeriod = 250;
int pulses = 6;

// read switch state
lhState = digitalRead(lhInput);
rhState = digitalRead(rhInput);
if (lhState == HIGH && rhState == LOW) {
disp_1(int a, int f);
}
if (lhState == LOW && rhState == HIGH) {
disp_2(a, b, d, g, h);
}
else {
slowBlink(delayPeriod, decimal);
}
}

void slowBlink(int delayPeriod, int decimal) {
for (int j = 0; j <= 3; j++) {
digitalWrite(decimal, HIGH);
delay(delayPeriod * 5);
digitalWrite(decimal, LOW);
delay(delayPeriod * 5);
}

// Display digit 1 on 7-segment display
void disp_1(int a, int f) {

// Turn on segments
digitalWrite(a, HIGH);
digitalWrite(f, HIGH);
delay(3000);
digitalWrite(a, LOW);
digitalWrite(f, LOW);
}

// Display digit 2 on 7-segment display
void disp_2(int a, int b, int d, int g, int h) {
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(d, HIGH);
digitalWrite(g, HIGH);
digitalWrite(h, HIGH);
delay(3000);
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(d, LOW);
digitalWrite(g, LOW);
digitalWrite(h, LOW);
}

You've missed a } to finish slowBlink() so you're trying to define the other 2 functions INSIDE slowBlink().

AutoFormat (Ctrl-T) makes that really obvious. Function definitions must always start at the far left of the page. Yours don't.

Steve

Shouldn't your program have setup() function in it ?

Why have you declared variables a to h twice ?

Please post your code in code tags as suggested in Read this before posting a programming question

And look where disp_1() and disp_2() are defined! You have to add some lib where they are defined or if defined here in this sketch, you cannot define it inside another function.

Also this is strange call for a function:

if (lhState == HIGH && rhState == LOW) {
    disp_1(int a, int f);
}

I have a bit reorganized your code, still not ideal.

No need for integer declarations for constant digital ports.
No need for parameters for disp_1() and disp_2().
No need for decimal parameter for slowBlink().

It is a bit weird to anyone use C/C++ that defines are in small letters, but anyway I have kept this way in order not to bring more unnecessary confusion in the code.

Is it that what you wanted?

 // Designate all 7seg terminals by alphabet (pursuant to diagram in journal)

#define a_ 4
#define b_ 5
#define c_ 6
#define d_ 7
#define e_ 8
#define f_ 9
#define g_ 10
#define h_ 11

// Define input pins
#define lhInput  2
#define rhInput  1

// delay and # of LED pulses
int delayPeriod = 250;
int pulses = 6;

void setup ()
{
  // Enable all 7-seg display to output
  pinMode(a_, OUTPUT);
  pinMode(b_, OUTPUT);
  pinMode(c_, OUTPUT);
  pinMode(d_, OUTPUT);
  pinMode(e_, OUTPUT);
  pinMode(f_, OUTPUT);
  pinMode(g_, OUTPUT);
  pinMode(h_, OUTPUT);

  // RH switch input
  pinMode(rhInput, INPUT);
  
  // LH switch input
  pinMode(lhInput, INPUT);
}

void loop() {

  // switch-state variables, initialized to false (no button presses)
  boolean lhState =  LOW;
  boolean rhState =  LOW;

  // delay to give the feel of a loop reset
  delay(2000);

  // read switch state
  lhState = digitalRead(lhInput);
  rhState = digitalRead(rhInput);

  if (lhState == HIGH && rhState == LOW) {
    disp_1();
  }
  if (lhState == LOW && rhState == HIGH) {
    disp_2();
  }
  else {
    //slowBlink(delayPeriod, decimal);
    slowBlink(delayPeriod); 
  }
}

void slowBlink(int delayPeriod) {
  for (int j = 0; j <= 3; j++) {
    digitalWrite(e_, HIGH);
    delay(delayPeriod * 5);
    digitalWrite(e_, LOW);
    delay(delayPeriod * 5);
  }

}

// Display digit 1 on 7-segment display
//void disp_1(byte a, byte f) {
void disp_1() {

  // Turn on segments
  digitalWrite(a_, HIGH);
  digitalWrite(f_, HIGH);
  delay(3000);
  digitalWrite(a_, LOW);
  digitalWrite(f_, LOW);
}

// Display digit 2 on 7-segment display
//void disp_2(byte a, byte b, byte d, byte g, byte h) {
void disp_2() {
  digitalWrite(a_, HIGH);
  digitalWrite(b_, HIGH);
  digitalWrite(d_, HIGH);
  digitalWrite(g_, HIGH);
  digitalWrite(h_, HIGH);
  delay(3000);
  digitalWrite(a_, LOW);
  digitalWrite(b_, LOW);
  digitalWrite(d_, LOW);
  digitalWrite(g_, LOW);
  digitalWrite(h_, LOW);
}
[\code]

noob314:
I have a bit reorganized your code, still not ideal.

No need for integer declarations for constant digital ports

You expect fractional ports?

[quote author=slipstick link=msg=4406038 date=1576347773]
You've missed a } to finish slowBlink() so you're trying to define the other 2 functions INSIDE slowBlink().

AutoFormat (Ctrl-T) makes that really obvious. Function definitions must always start at the far left of the page. Yours don't.

Steve 
[/quote]

SMH...I swear I spent half an hour just checking basic syntax stuff like that.  Appreciated.

[quote author=noob314 link=msg=4406097 date=1576352286]
I have a bit reorganized your code, still not ideal. 

No need for integer declarations for constant digital ports.
No need for parameters for disp_1() and  disp_2().
No need for decimal parameter for slowBlink().

It is a bit weird to anyone use C/C++ that defines are in small letters, but anyway I have kept this way in order not to bring more unnecessary confusion in the code.


[\code]

noob314:
Appreciate the headsup on the naming convention. Is that convention so that it doesn't appear as though I had an incomplete variable name?

UKHeliBob:
Shouldn't your program have setup() function in it ?

Why have you declared variables a to h twice ?

Please post your code in code tags as suggested in Read this before posting a programming question

Double-declared them. Thanks for catchin that.