Go Down

Topic: 7 Segment Library for Arduino 1.0 (Read 2 times) previous topic - next topic

Qtechknow

Hi all,
Thanks for the help.  I have edited the code, but in my example program, it gives me a ton of error messages.  Here is the current .h file. 
 
Code: [Select]
#ifndef Soda_h
#define Soda_h

#include "Arduino.h"

class Soda
{
public:
    uint8_t pins(int a, int b, int c, int d, int e, int f, int g, int dp);
    void write(int number);
   
private:
    int _a, _b, _c, _d, _e, _f, _g, _dp, _number;
    const byte numeral[10];
    const int segmentPins[8];
   
#endif


And here is the latest .cpp file.

Code: [Select]
#include "Arduino.h"
#include "Soda.h"

uint8_t Soda::pins(int a, int b, int c, int d, int e, int f, int g, int dp) {
   
    a=_a;
    b=_b;
    c=_c;
    d=_d;
    e=_e;
    f=_f;
    g=_g;
    dp=_dp;
   
    segmentPins[0] = _dp;
    segmentPins[1] = _g;
    segmentPins[2] = _f;
    segmentPins[3] = _e;
    segmentPins[4] = _d;
    segmentPins[5] = _c;
    segmentPins[6] = _b;
    segmentPins[7] = _a;
   
    for(int i=0; i < 8; i++) {
       
        pinMode(segmentPins[i], OUTPUT);
    }
   
   
}

void Soda::write(int number) {
    boolean isBitSet;
   
    numeral[0] = B11111100;  // 0
    numeral[1] = B01100000;  // 1
    numeral[2] = B11011010;  // 2
    numeral[3] = B11110010;  // 3
    numeral[4] = B01100110;  // 4
    numeral[5] = B10110110;  // 5
    numeral[6] = B10111110;  // 6
    numeral[7] = B11100000;  // 7
    numeral[8] = B11111110;  // 8
    numeral[9] = B11100110;  // 9
   
    for(int segment=1; segment < 8; segment++) {
        if(number < 0 || number > 9) {
            isBitSet = 0;
        }else{
            isBitSet = bitRead(numeral[number], segment);
        }
        isBitSet = ! isBitSet;
        digitalWrite(segmentPins[segment], isBitSet);
    }
}


And here is the example code in the Arduino IDE.

Code: [Select]
// Soda Demo

#include "Soda.h"

void setup() {
  Soda.pins(2, 3, 4, 5, 6, 7, 8, 9);
}

void loop() {
  for(int i=0; i<10; i++) {
    Soda.write(i);
    delay(1000);
  }
}


I get the following error messages after I compile.

Code: [Select]

SodaDemo:4: error: 'void Soda::setup()' cannot be overloaded
SodaDemo:2: error: with 'void Soda::setup()'
SodaDemo:8: error: 'void Soda::loop()' cannot be overloaded
SodaDemo:3: error: with 'void Soda::loop()'
SodaDemo:13: error: expected `}' at end of input
SodaDemo.cpp: In member function 'void Soda::setup()':
SodaDemo:5: error: expected unqualified-id before '.' token
SodaDemo.cpp: In member function 'void Soda::loop()':
SodaDemo:10: error: expected unqualified-id before '.' token
SodaDemo.cpp: At global scope:
SodaDemo:13: error: expected unqualified-id at end of input


Any help?

lloyddean

#6
Apr 14, 2012, 08:22 pm Last Edit: Apr 14, 2012, 09:12 pm by lloyddean Reason: 1
Soda.h

Needs '};' before '#endif'

Soda.cpp

Your assignments

   a=_a;
   ...

need to be reversed

  _a=a;

Soda Demo

 Soda.pins(2, 3, 4, 5, 6, 7, 8, 9);

In this case 'pins(...)' is NOT a class method.

You probably meant something along the line of (at global scope)

   Soda    soda;

and change all occurences of 'Soda.' with 'soda.'

Example

    soda.pins(2, 3, 4, 5, 6, 7, 8, 9);

etc ...

EDIT:  There may be other issues as I didn't spend much time looking at, or bother trying, to compile the code you provided

Qtechknow

Thanks for the replies. I still have the following error message though.

Code: [Select]

SodaDemo:2: error: new types may not be defined in a return type
SodaDemo.cpp:6: note: (perhaps a semicolon is missing after the definition of 'Soda')
SodaDemo:2: error: two or more data types in declaration of 'setup'
SodaDemo:4: error: structure 'soda' with uninitialized const members


Could anyone help?

WizenedEE

You need to make an instance of the Soda object before you can use it:
Code: [Select]

Soda digit;

void setup() {
  digit.pins(...);
}

void loop() {
  digit.write(...);
}


If you get more errors, please post the latest revision again, so we don't have to guess at what changes you made.

Qtechknow

Sorry for the confusion.  Here are the latest files.  I am still getting an error message though.

Soda Demo:

Code: [Select]
// Soda Demo

#include "Soda.h"

Soda soda;

void setup() {
  soda.pins(2, 3, 4, 5, 6, 7, 8, 9);
}

void loop() {
  for(int i=0; i<10; i++) {
    soda.write(i);
    delay(1000);
  }
}


Soda.h

Code: [Select]
#ifndef Soda_h
#define Soda_h

#include "Arduino.h"

class Soda
{
public:
    uint8_t pins(int a, int b, int c, int d, int e, int f, int g, int dp);
    void write(int number);
   
private:
    int _a, _b, _c, _d, _e, _f, _g, _dp, _number;
    const byte numeral[10];
    const int segmentPins[8];
}

#endif


Soda.cpp
Code: [Select]
#include "Soda.h"

uint8_t Soda::pins(int a, int b, int c, int d, int e, int f, int g, int dp) {

    _a=a;
    _b=b;
    _c=c;
    _d=d;
    _e=e;
    _f=f;
    _g=g;
    _dp=dp;
   
    segmentPins[0] = _dp;
    segmentPins[1] = _g;
    segmentPins[2] = _f;
    segmentPins[3] = _e;
    segmentPins[4] = _d;
    segmentPins[5] = _c;
    segmentPins[6] = _b;
    segmentPins[7] = _a;
   
    for(int i=0; i < 8; i++) {
       
        pinMode(segmentPins[i], OUTPUT);
    }
   
   
}

void Soda::write(int number) {
    boolean isBitSet;
   
    numeral[0] = B11111100;  // 0
    numeral[1] = B01100000;  // 1
    numeral[2] = B11011010;  // 2
    numeral[3] = B11110010;  // 3
    numeral[4] = B01100110;  // 4
    numeral[5] = B10110110;  // 5
    numeral[6] = B10111110;  // 6
    numeral[7] = B11100000;  // 7
    numeral[8] = B11111110;  // 8
    numeral[9] = B11100110;  // 9
   
    for(int segment=1; segment < 8; segment++) {
        if(number < 0 || number > 9) {
            isBitSet = 0;
        }else{
            isBitSet = bitRead(numeral[number], segment);
        }
        isBitSet = ! isBitSet;
        digitalWrite(segmentPins[segment], isBitSet);
    }
}


And here is the same error message that comes up with soda demo.

Code: [Select]
SodaDemo:2: error: new types may not be defined in a return type
SodaDemo.cpp:6: note: (perhaps a semicolon is missing after the definition of 'Soda')
SodaDemo:2: error: two or more data types in declaration of 'setup'
SodaDemo:4: error: structure 'soda' with uninitialized const members


Any Help?

Thanks,
Qtechknow

Go Up