Error - 'Bounce' Does not name a type

Hi guys,

I’m very new to this stuff and am trying to upload code to my Nano 3.0 but its coming up with errors.

I’m using the Arduino 3.0 w/ATmega328 to use a set of CST/Five Star Simulations sim racing pedals to work with the Fanatec CSW wheel base on the PS3, I have them working fine individually on the PC but want to make them work with the PS3 as well.

A guy on the GTPlanet forums did all the schematic and programming and uploaded it, I’ve followed his schematic and downloaded the Arduino 1.0.5-r2 software, created a new sketch, opened my file (pedals.ino), set the board to arduino nano w/ATmega328 and set com port to #3.

When I verify or try to upload it comes up with an error ‘Adafruit_MCP4725’ does not name a type

I’ve attached a copy of the code below, error message and INO file and schematic in a zip file to help demonstrate what I’m trying to do.

In the code below there was //comments everywhere, I had to delete them all as the post can only have 9500 characters, all the comments will be in the pedals.ino file if you need clarification on anything.

Thanks in advance for your help

//#define _DEBUG_ALL_
//#define _DEBUG_EEPROM_

#define USE_EEPROM
#define USE_DAC

#ifdef _DEBUG_EEPROM_
	#define _EEPROMEX_DEBUG
#endif

#ifdef USE_DAC
	#include <Wire.h>				
	#include <Adafruit_MCP4725.h>	
#endif

#include <Bounce2.h>				

#ifdef USE_EEPROM
	#include <EEPROMex.h>
#endif

#define SERIAL_SPEED 9600

// Analog Pin definitions
#define THROTTLE_IN				0			
#define BRAKE_IN				1			
#define CLUTCH_IN				2			

// Digital Pin definitions
#define CALIBRATE_PIN			2		
#define THROTTLE_INVERT_PIN		10		
#define BRAKE_INVERT_PIN		9		
#define SPARE_DIP_3				8		
#define GREEN_LED_PIN			11		
#define RED_LED_PIN				12		 

int throttleStart;					
int throttleEnd;					
int brakeStart;						
int brakeEnd;						

int configAddress	= 0;			
struct conf
{
int throttleMin;					
int throttleMax;					
int brakeMin;						
int brakeMax;						
} config = { 0 , 1023 , 0 , 1023 }; // Default to full 10 bit ADC

#ifdef USE_DAC
Adafruit_MCP4725 throttleDAC;		// 12 Bit DAC for the throttle output to Fanatec CSW
Adafruit_MCP4725 brakeDAC;			// 12 Bit DAC for the clutch output to Fanatec CSW
#endif

#define BLINK			0x2			
#define BLINK_INTERVAL	250			
#define GREEN_LED			0		
#define RED_LED				1		 
struct								
{
	boolean blink;					
	int pin;						
	int state;						
	unsigned long previousMillis;	
} ledState[2] = { { false , GREEN_LED_PIN , LOW , 0L } , { false , RED_LED_PIN , LOW , 0L } };

#define DEBOUNCE_TIME	500		
Bounce calibrateButton;			


int calibrateState		= 0;

void setup()
{
	#ifdef _DEBUG_ALL_
	// Initialise Serial connections
	Serial.begin( SERIAL_SPEED );
	Serial.println( "setup() Started" );
	#endif

	// Read config from EEPROM
	readEEPROM();

	
	pinMode( CALIBRATE_PIN , INPUT_PULLUP );

	
	pinMode( THROTTLE_INVERT_PIN , INPUT_PULLUP );
	pinMode( BRAKE_INVERT_PIN , INPUT_PULLUP );
	
	
	calibrateButton.attach( CALIBRATE_PIN );
	calibrateButton.interval( DEBOUNCE_TIME );

	
	pinMode( ledState[RED_LED].pin , OUTPUT );
	pinMode( ledState[GREEN_LED].pin , OUTPUT );
	setLED( RED_LED , LOW );
	setLED( GREEN_LED , LOW );

	
	analogReference( DEFAULT );
	
	

	#ifdef USE_DAC
	
	throttleDAC.begin( 0x62 );
	brakeDAC.begin( 0x63 );
	#endif
	
	
	if ( digitalRead( THROTTLE_INVERT_PIN ) == LOW )
	{ throttleStart = 4095; throttleEnd = 0; }
	else
	{ throttleStart = 0; throttleEnd = 4095; }
	
	if ( digitalRead( BRAKE_INVERT_PIN ) == LOW )
	{ brakeStart = 4095; brakeEnd = 0; }
	else
	{ brakeStart = 0; brakeEnd = 4095; }
	
	#ifdef	_DEBUG_ALL_
	Serial.println( "setup() Finished" );
	#endif
}

void loop()
{
	unsigned int t;
	unsigned int b;
	
	
	if ( checkCalibrationState() != 0 ) return;
	
	
	t = analogRead( THROTTLE_IN );
	b = analogRead( BRAKE_IN );
  
	#ifdef _DEBUG_ALL_
	Serial.print( "TMin:" ); Serial.print( config.throttleMin ); 
	Serial.print( " TMax:" ); Serial.print( config.throttleMax ); 
	Serial.print( " BMin:" ); Serial.print( config.brakeMin ); 
	Serial.print( " BMax:" ); Serial.print( config.brakeMax ); 
	Serial.print( " TStart:" ); Serial.print( throttleStart );
	Serial.print( " TEnd:" ); Serial.print( throttleEnd );
	Serial.print( " BStart:" ); Serial.print( brakeStart );
	Serial.print( " BEnd:" ); Serial.print( brakeEnd );
	Serial.print( " TOld:" ); Serial.print( t );
	Serial.print( " BOld:" ); Serial.print( b );
	#endif

	
  	t = constrain( t , config.throttleMin , config.throttleMax );
	t = map( t , config.throttleMin , config.throttleMax , throttleStart , throttleEnd );
	#ifdef USE_DAC
	throttleDAC.setVoltage( t , false );
	#endif
	
	
  	b = constrain( b , config.brakeMin , config.brakeMax );
	b = map( b , config.brakeMin , config.brakeMax , brakeStart , brakeEnd );
	#ifdef USE_DAC
	brakeDAC.setVoltage( b , false );
	#endif
	
	#ifdef _DEBUG_ALL_	
	Serial.print( " TNew:" ); Serial.print( t );
	Serial.print( " BNew:" ); Serial.println( b );
	#endif
}

int checkCalibrationState()
{             
	
	blinkLED( GREEN_LED ); blinkLED( RED_LED );
	
	
	boolean stateChanged = calibrateButton.update();
	int state = calibrateButton.read();
  
	
	if ( stateChanged && state == LOW )
	{
		#ifdef _DEBUG_ALL_
		Serial.print( "Calibration Change detected. Before:" );
		Serial.print( calibrateState );
		Serial.print( " After:" );
		#endif
		
		calibrateState = (calibrateState + 1)%5;
		switch( calibrateState )
		{
		case 1: setLED( GREEN_LED , HIGH ); break;
		case 2: config.throttleMin = analogRead( THROTTLE_IN ); setLED( GREEN_LED , BLINK ); break;
		case 3: config.throttleMax = analogRead( THROTTLE_IN ); setLED( GREEN_LED , LOW ); setLED( RED_LED , HIGH ); break;
		case 4: config.brakeMin = analogRead( BRAKE_IN ); setLED( RED_LED , BLINK ); break;
		case 0: config.brakeMax = analogRead( BRAKE_IN ); writeEEPROM(); setLED( RED_LED , LOW ); break; // Be explicit and use 0, don't burn out eeprom if error
		default: break;
		}
		
		#ifdef _DEBUG_ALL_
		Serial.println( calibrateState );
		#endif
	}
	
	return calibrateState;
}

void setLED( int led , int state )
{
	if ( state == BLINK )
	{
		ledState[led].blink = true;
		ledState[led].previousMillis = millis();
		state = LOW;
	}
	else ledState[led].blink = false;
	
	ledState[led].state = state;
	digitalWrite( ledState[led].pin , state );
}

void blinkLED( int led )
{
	if ( !ledState[led].blink ) return;
	
	unsigned long currentMillis = millis();
 
	if ( ( currentMillis - ledState[led].previousMillis) > BLINK_INTERVAL )
	{
		
		ledState[led].previousMillis = currentMillis;  

		
		if ( ledState[led].state == LOW )
			setLED( led , HIGH );
		else
			setLED( led , LOW );
		ledState[led].blink = true;
	}
}

// EEPROM Functions
void readEEPROM()
{
	#ifdef USE_EEPROM
	
	EEPROM.setMemPool( 0 , EEPROMSizeNano );
  
	 
	EEPROM.setMaxAllowedWrites( 100 );
	
	
	configAddress  = EEPROM.getAddress( sizeof( struct conf ) );
	
	
	EEPROM.readBlock<struct conf>( configAddress, config );
	#endif
	
	#ifdef _DEBUG_EEPROM_
	Serial.print( "Address:" ); Serial.println( configAddress ); 
	Serial.print( "sizeof(struct config):" ); Serial.println( sizeof( struct conf ) ); 
	Serial.print( "throttleMin:" ); Serial.print( config.throttleMin ); 
	Serial.print( " throttleMax:" ); Serial.println( config.throttleMax ); 
	Serial.print( "brakeMin:" ); Serial.print( config.brakeMin ); 
	Serial.print( " brakeMax:" ); Serial.println( config.brakeMax ); 
	#endif
}

void writeEEPROM()
{
	#ifdef USE_EEPROM
	int i;
	
	
	if ( config.throttleMax < config.throttleMin ) { i = config.throttleMax; config.throttleMax = config.throttleMin; config.throttleMin = i; }
	if ( config.brakeMax < config.brakeMin ) { i = config.brakeMax; config.brakeMax = config.brakeMin; config.brakeMin = i; }
	
	
	EEPROM.writeBlock<struct conf>( configAddress , config );
	#endif
}

Fanatec_CST_Diagrams_And_Code (2).zip (2.56 MB)

And... have you installed the Adafruit MCP4725 library...?

majenko: And... have you installed the Adafruit MCP4725 library...?

Thanks for the reply

No I haven't done that, how do I do that?

http://bit.ly/1jw355E

https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

Adafruit not only produces some very solid libraries for sensors they sell, but they provide some of the best instructions for installing and using those libraries.

Excellent, thank you

Ok so I got the Adafruit MCP4725 library to work.

Now I have the following errors still coming up, I loaded a Bounce library but that didn't fix the first error.

pedals:69: error: 'Bounce' does not name a type
pedals.ino: In function 'void setup()':
pedals:101: error: 'calibrateButton' was not declared in this scope
pedals.ino: In function 'int checkCalibrationState()':
pedals:194: error: 'calibrateButton' was not declared in this scope
pedals.ino: In function 'void readEEPROM()':
pedals:264: error: 'EEPROM' was not declared in this scope
pedals:264: error: 'EEPROMSizeNano' was not declared in this scope
pedals:273: error: expected primary-expression before 'struct'
pedals:273: error: expected `;' before 'struct'
pedals.ino: In function 'void writeEEPROM()':
pedals:296: error: 'EEPROM' was not declared in this scope
pedals:296: error: expected primary-expression before 'struct'
pedals:296: error: expected `;' before 'struct'

Did you stop/start the IDE after installing the new library ?

UKHeliBob: Did you stop/start the IDE after installing the new library ?

I closed the IDE (software program) down and opened it up again, is that what you mean?

I'm not familiar with the EEPROM library you're using - EEPROMex.h. You will need to install that as well, from wherever it is...

anyone else able to help, I'm still unable to get the Bounce to work and the rest of the errors coming up.

Have you tried looking for (and installing) the EEPROMex library?

Yeah i did try that but mustn't have installed it properly, installed and that is now working.

Still left with the Bounce and calibration errors as per below if anybody can help.

Really appreciate all the help so far guys, thanks.

pedals:69: error: 'Bounce' does not name a type
pedals.ino: In function 'void setup()':
pedals:101: error: 'calibrateButton' was not declared in this scope
pedals.ino: In function 'int checkCalibrationState()':
pedals:194: error: 'calibrateButton' was not declared in this scope

I think this is all the code that Bounce is relevant to

#define DEBOUNCE_TIME   500     // Debounce stable ON time in ms
Bounce calibrateButton;         // Debounce on calibration button

// Current state of the calibration mode
//  0 - Not calibrating , LEDS OFF
//  1 - Throttle Min   Green ON    Red OFF
//  2 - Throttle Max   Green Blink Red OFF
//  3 - Brake Min      Green OFF   Red ON
//  4 - Brake Max      Green OFF   Red Blink
int calibrateState      = 0;

void setup()
{
    #ifdef _DEBUG_ALL_
    // Initialise Serial connections
    Serial.begin( SERIAL_SPEED );
    Serial.println( "setup() Started" );
    #endif

    // Read config from EEPROM
    readEEPROM();

    // Setup the calibration button, enable internal pullup
    pinMode( CALIBRATE_PIN , INPUT_PULLUP );

    // And the Throttle/Brake Invert DIP Switches
    // No need to debounce, static DIP switch
    // Enable internal pullup, floating bitch ;-)
    pinMode( THROTTLE_INVERT_PIN , INPUT_PULLUP );
    pinMode( BRAKE_INVERT_PIN , INPUT_PULLUP );

    // After setting up the button, setup Bounce object, using STABLE ON not LOCK-OUT
    // Signal needs to be stable for DEBOUNCE_INTERVAL amount of milliseconds
    calibrateButton.attach( CALIBRATE_PIN );
    calibrateButton.interval( DEBOUNCE_TIME );

    // Make sure the LEDS are OFF
    pinMode( ledState[RED_LED].pin , OUTPUT );
    pinMode( ledState[GREEN_LED].pin , OUTPUT );
    setLED( RED_LED , LOW );
    setLED( GREEN_LED , LOW );

    // Be explicit, not necessary but just in case.
    // If set to EXTERNAL will short VCC to AREF on first readAnalog()!!!!!
    analogReference( DEFAULT );

    // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
    // For MCP4725A0 the address is 0x60 or 0x61
    // For MCP4725A2 the address is 0x64 or 0x65

    #ifdef USE_DAC
    // Initialise the throttle and brake 12 Bit DAC's
    throttleDAC.begin( 0x62 );
    brakeDAC.begin( 0x63 );
    #endif

    // Should have been enough time to let DIP switches settle
    // LOW = Invert ON since internal pullups enabled.
    // Too lazy to solder extra pull downs ;p
    if ( digitalRead( THROTTLE_INVERT_PIN ) == LOW )
    { throttleStart = 4095; throttleEnd = 0; }
    else
    { throttleStart = 0; throttleEnd = 4095; }

    if ( digitalRead( BRAKE_INVERT_PIN ) == LOW )
    { brakeStart = 4095; brakeEnd = 0; }
    else
    { brakeStart = 0; brakeEnd = 4095; }

    #ifdef  _DEBUG_ALL_
    Serial.println( "setup() Finished" );
    #endif
}

void loop()
{
    unsigned int t;
    unsigned int b;

    // Check for Calibration first
    if ( checkCalibrationState() != 0 ) return;

    // Make sure reference not EXTERNAL !!!
    // read , constrain and map the value from throttle and brake
    t = analogRead( THROTTLE_IN );
    b = analogRead( BRAKE_IN );
  
    #ifdef _DEBUG_ALL_
    Serial.print( "TMin:" ); Serial.print( config.throttleMin ); 
    Serial.print( " TMax:" ); Serial.print( config.throttleMax ); 
    Serial.print( " BMin:" ); Serial.print( config.brakeMin ); 
    Serial.print( " BMax:" ); Serial.print( config.brakeMax ); 
    Serial.print( " TStart:" ); Serial.print( throttleStart );
    Serial.print( " TEnd:" ); Serial.print( throttleEnd );
    Serial.print( " BStart:" ); Serial.print( brakeStart );
    Serial.print( " BEnd:" ); Serial.print( brakeEnd );
    Serial.print( " TOld:" ); Serial.print( t );
    Serial.print( " BOld:" ); Serial.print( b );
    #endif

    // Adjust throttle output, inverting if necessarry
   t = constrain( t , config.throttleMin , config.throttleMax );
    t = map( t , config.throttleMin , config.throttleMax , throttleStart , throttleEnd );
    #ifdef USE_DAC
    throttleDAC.setVoltage( t , false );
    #endif

    // Adjust brake output, inverting if necessarry
   b = constrain( b , config.brakeMin , config.brakeMax );
    b = map( b , config.brakeMin , config.brakeMax , brakeStart , brakeEnd );
    #ifdef USE_DAC
    brakeDAC.setVoltage( b , false );
    #endif

    #ifdef _DEBUG_ALL_  
    Serial.print( " TNew:" ); Serial.print( t );
    Serial.print( " BNew:" ); Serial.println( b );
    #endif
}

int checkCalibrationState()
{             
    // Blink LED's if required
    blinkLED( GREEN_LED ); blinkLED( RED_LED );

    // Check for Calibration first
    boolean stateChanged = calibrateButton.update();
    int state = calibrateButton.read();
  
    // Detect the falling edge, with BOUNCE_INTERVAL detection
    if ( stateChanged && state == LOW )
    {
        #ifdef _DEBUG_ALL_
        Serial.print( "Calibration Change detected. Before:" );
        Serial.print( calibrateState );
        Serial.print( " After:" );
        #endif

        calibrateState = (calibrateState + 1)%5;
        switch( calibrateState )
        {
        case 1: setLED( GREEN_LED , HIGH ); break;
        case 2: config.throttleMin = analogRead( THROTTLE_IN ); setLED( GREEN_LED , BLINK ); break;
        case 3: config.throttleMax = analogRead( THROTTLE_IN ); setLED( GREEN_LED , LOW ); setLED( RED_LED , HIGH ); break;
        case 4: config.brakeMin = analogRead( BRAKE_IN ); setLED( RED_LED , BLINK ); break;
        case 0: config.brakeMax = analogRead( BRAKE_IN ); writeEEPROM(); setLED( RED_LED , LOW ); break; // Be explicit and use 0, don't burn out eeprom if error
        default: break;
        }

        #ifdef _DEBUG_ALL_
        Serial.println( calibrateState );
        #endif
    }

    return calibrateState;
}

You didn't install it correctly or it's not the right library that you need

Arrch:
You didn’t install it correctly or it’s not the right library that you need

Just noticed I hadn’t installed Bounce2 properly

Thanks all good now