CapSense does not name a type error

Hi all.

I have been playing with the CapSense circuit in the reference library and am experiencing the following frustrations.

I keep getting the error "sketch_sep20c:7: error: 'CapSense' does not name a type" when I compile.

And I'm a little shaky on variations of circuits etc. and if I am wiring everything right. The reference library page lacks a schematic. I'm a newbie so I am missing something.

Any help or a point in the right direction would be grand.

Hi Adam

Can you post your code. Use code tags (the '#' button above the row of smileys).

Did you get the CapacitiveSensor library from this page? Arduino Playground - CapacitiveSensor

Which version of the library did you download? And are you running on a Uno?

Thanks

Ray

Hackscribble:
Hi Adam

Can you post your code. Use code tags (the '#' button above the row of smileys).

Did you get the CapacitiveSensor library from this page? Arduino Playground - HomePage

Which version of the library did you download? And are you running on a Uno?

Thanks

Ray

Thanks for your willingness to help, Ray!!!
Yes, I got the code by downloading the library at that page, the 4.0 zip. And, yes, I am using Uno.
Here is the code.

#include <CapacitiveSensor.h>

/*
 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Uses a high value resistor e.g. 10M between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 */


CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil

void setup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
}

void loop()                    
{
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);
    long total2 =  cs_4_6.capacitiveSensor(30);
    long total3 =  cs_4_8.capacitiveSensor(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing

    Serial.print(total1);                  // print sensor output 1
    Serial.print("\t");
    Serial.print(total2);                  // print sensor output 2
    Serial.print("\t");
    Serial.println(total3);                // print sensor output 3

    delay(10);                             // arbitrary delay to limit data to serial port 
}

Program compiles OK for me, so likely to be a problem in how the library has been installed on your system.

Did you use the version 04 in the zip file or the version 05 from GitHub? Both are linked from that page.

Hmm. Yes I downloaded the 4 zip file, and just saved to my Arduino examples file.

These are the error messages I get when I compile:

CapacitiveSensorSketch:12: error: 'CapacitiveSensor' does not name a type
CapacitiveSensorSketch:13: error: 'CapacitiveSensor' does not name a type
CapacitiveSensorSketch:14: error: 'CapacitiveSensor' does not name a type
CapacitiveSensorSketch.pde: In function 'void setup()':
CapacitiveSensorSketch:18: error: 'cs_4_2' was not declared in this scope
CapacitiveSensorSketch.pde: In function 'void loop()':
CapacitiveSensorSketch:25: error: 'cs_4_2' was not declared in this scope
CapacitiveSensorSketch:26: error: 'cs_4_6' was not declared in this scope
CapacitiveSensorSketch:27: error: 'cs_4_8' was not declared in this scope

Adam3B:
Hmm. Yes I downloaded the 4 zip file, and just saved to my Arduino examples file.

If you meant examples, there's your issue - it should be in your personal libraries directory

Inside the version 4 zip, you need to drill down through various levels of folder until you get to one called "CapacitiveSensor". Extract that folder and put it into your libraries folder as wildbill says.

Ah, I see what you all are saying but am not being successful with getting it to the right place! garr windows 8.
when I downloaded it and went to extract, I clicked on my documents library, then to the Arduino file, then "libraries", created a folder called CAp Sense and clicked save. But when I open the compiler and go to open a file, it makes me open the actual Capacitive Sensor folder to a .cpp or .h file (and a keyword and read me). not an actual sketch. IDK. when it was in examples ity opened the sketch and code (although it wouldn't compile with said errors).

Try this. Extract the "CapacitiveSensor" folder from the zip file and save it on your desktop.

In Arduino, click on Sketch - Import Library - Add Library. Select the folder on your desktop and hit OK. You should get a message saying that the library has been installed.

If you look in Files - Examples, there should then be a folder for CapacitiveSensor with the example program in it.

I need help with my much error with this code

try2.ino:4:2: error: invalid preprocessing directive #CapacitiveSensor
try2.ino: In function 'void loop()':
try2:19: error: 'cs_2_3' was not declared in this scope
try2:20: error: 'cs_2_4' was not declared in this scope
try2.ino: At global scope:
try2:42: error: 'look' does not name a type

//////////////////////////////////////////
#include <CapacitiveSensor.h>

#CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);

int velocity = 100;//velocity of MIDI notes, must be between 0 and 127
//(higher velocity usually makes MIDI instruments louder)

int noteON = 144;//144 = 10010000 in binary, note on command

void setup() {
// Set MIDI baud rate:
Serial.begin(31250);

}

void loop() {

long total1 = cs_2_3.capacitiveSensor(30);
long total2 = cs_2_4.capacitiveSensor(30);

if (total1 > 500) {

for (int note=48;note<49;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(500);
MIDImessage(noteON, note, 0);}}//turn note off

if (total2 > 500) {
for (int note=49;note<50;note++) {//from note 50 (D3) to note 69 (A4)
MIDImessage(noteON, note, velocity);//turn note on
delay(500);//hold note for 300ms
MIDImessage(noteON, note, 0);}}//turn note off

}
//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
}
look here too
http://forum.arduino.cc/index.php?topic=210505.0

try2.ino:4:2: error: invalid preprocessing directive #CapacitiveSensor``#CapacitiveSensor cs_2_4 = CapacitiveSensor(2,4);
In any of the examples you've worked on, have you ever seen a construct like that? (Hint: I haven't).

Please use code tags when posting code.