How can I count an event?

Alright so for my first project I am going to be using an attiny for a touch sensor, and leds will light up depending how many times it detects a touch (or button press or whatever).

I thought that this might work but sadly it did not.

#include <CapacitiveSensor.h>

CapacitiveSensor   cs_1_2 = CapacitiveSensor(1,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
int ledpin = 0;
int countnumber = 0;


void setup()                    
{
  cs_1_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
  pinMode (ledpin, OUTPUT);
}

void loop()                    
{
  long start = millis();
  long total1 =  cs_1_2.capacitiveSensor(30);
  if (total1 < 99) {
   
  }
  if (countnumber = 1) {
    digitalWrite(ledpin, HIGH);
  }
}

The code checked out fine but it didn’t do squat.

Basically I am looking for something like var in batch pogramming, and using multiple loops or something like that. Var would start as 0, if it got touched once it would change to 1, and the first led would light up, and it would move to the next loop, if it was touched a second time var would change again, the next led would light up and so forth.

I’m having trouble with this so any help is greatly appreciated. I’ve tried all number of things using stuff I’ve seen in other codes but it refuses to work.

 if (countnumber = 1) {

C/C++ programming 101: The assignment vs. equality operators

The only capacitive sensor I've used was made of tin foil and paper by myself. I connected it to an UNO and played around with it watching the data on the serial monitor. To cut down on the print flow I only printed data that varied from the last value by more than 10 or 20 points yet what I saw showed me that I could tell when I actually touched the sensor as opposed to when my finger came close. The data changed all the way down to the touch and continued to change if I put more pressure on. The way I could tell touch from non-touch was a sudden jump to lower values.

From what I saw, making a debounce routine would take more work than for a button or switch and that routine take longer to detect a touch.

How does your capacitive sensor compare? Did you make it or buy it?

GoForSmoke:
The only capacitive sensor I've used was made of tin foil and paper by myself. I connected it to an UNO and played around with it watching the data on the serial monitor. To cut down on the print flow I only printed data that varied from the last value by more than 10 or 20 points yet what I saw showed me that I could tell when I actually touched the sensor as opposed to when my finger came close. The data changed all the way down to the touch and continued to change if I put more pressure on. The way I could tell touch from non-touch was a sudden jump to lower values.

From what I saw, making a debounce routine would take more work than for a button or switch and that routine take longer to detect a touch.

How does your capacitive sensor compare? Did you make it or buy it?

I made one using the instructions from the capsense library page, it works great, and I can use it to trigger an LED just fine.

This is my first project though, I haven't looked into arduino code before today, that's why I'm having trouble.

AWOL:

 if (countnumber = 1) {

C/C++ programming 101: The assignment vs. equality operators

is arduino coding C? I just replied to the other guy, first time touching arduino code today, only other programming experience is batch and a bit of vbs.

Yes, it is C++.

XOIIO:
is arduino coding C?

Yes, I believe I might have mentioned that in the "sticky" at the start of this forum section.

Point 1.

It's amazing how much time you can save by reading all the "read me" stuff.

well a combination of being up over 24 hours, on pain killers and wisdom teeth kicking my ass I'm not looking around as much as a normally would be.

Anyways, I am still looking for a solution to this.

I'd add some debug prints - no point in trying black-box debugging in a new environment.

AWOL:
I'd add some debug prints - no point in trying black-box debugging in a new environment.

By that are you saying that the code I have should be working?

Have you fixed the = instead of == bug ?
Inserting Serial.prints at strategic points in your code will let you find out if it is doing what you think it should and help track down problems. For instance, what is the value of countnumber just before the if statement ? Does it vary ? Is it ever 1 ?

UKHeliBob:
Have you fixed the = instead of == bug ?
Inserting Serial.prints at strategic points in your code will let you find out if it is doing what you think it should and help track down problems. For instance, what is the value of countnumber just before the if statement ? Does it vary ? Is it ever 1 ?

I'm working on getting the serial thing to work, I keep getting "Serial" was not defined in this scope.

I'm not sure what you are reffering to with the == bug

Check reply #1.

By that are you saying that the code I have should be working?

I have no idea - I don't have your hardware or your libraries and I can't see how you have wired it up, but I'd certainly be putting in some indicators to show me that what I'm doing is returning results that look sensible. Like debug prints.

AWOL:

By that are you saying that the code I have should be working?

I have no idea - I don't have your hardware or your libraries and I can't see how you have wired it up, but I'd certainly be putting in some indicators to show me that what I'm doing is returning results that look sensible. Like debug prints.

well I still haven't gotten past that darn "Serial" was not defined in this scope message, I'm not sure why it won't work properly, I did fix the "==" thing.

I'm thinking that maybe serial print doesn't work with an attiny85?

Where did that library come from?

#include <CapacitiveSensor.h>

How to use this forum

Sore tooth or not, you are making us work hard to help you.

If you are using a library that does not come with the IDE (in other words, you downloaded it from somewhere) please post a link to this library.

XOIIO:
I'm working on getting the serial thing to work, I keep getting "Serial" was not defined in this scope.

Use this core...
http://code.google.com/p/arduino-tiny/
...and a TTL-serial-to-USB converter.

Even better, use this version of the ArduinoISP sketch...

...with this library...

Well here it is, although I don't see how the library relates to my question, which is just asking for a simple way to count an event or use a variable to count.
http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense

I am using that core, but I'll look into that other arduino isp sketch, I used this tutorial Index of /