Hi all helpfull people.
With my UNO I made a matrix of 10 capasitive sensors (dig.input pin2-12) associated with the analog pins as dig.output for 10 LEDs via a Shift register 74HC595.
I tested the shift reg. acc.to tutorial ShiftOut and it worked for 8 output.
Separatly I tested the capasitive pads with tutorial for this , whitch worked.
To shorten the code i implemented loop with array, and there starts the problem.
I have searched for tips and changed my code acc.to those, many times, but ends up with:
"CapSensor cant be used as a function" , "variable-sized object 'capSensor' may not be initialized", and finaly: "TEST_ShiftOut-IF-Array-_RETTET.ino: In function 'void loop()':
TEST_ShiftOut-IF-Array-_RETTET.ino:36:32: error: request for member 'capacitiveSensor' in 'array[T]', which is of non-class type 'int' ....
Here is the code that will not compile:
// Name: TEST_ShiftOut-IF -> CapSensor m Array for tak 1-8 + 9-10
//****************************************************************
#include <CapacitiveSensor.h>
int latchPin = 17; //Pin connected to ST_CP of 74HC595
int clockPin = 18; //Pin connected to SH_CP of 74HC595
int dataPin = 19; //Pin connected to DS of 74HC595
int array[10] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; //Array for dig.pinner IN from sensor.
int sensorValue[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //Array for values to check.
int threshold = 10000;
int TAK[8] = {1, 2, 4, 8, 16, 32, 64, 128}; //Writes to touched Shift-pin // line10
int T;
int capSensor(int x);
CapacitiveSensor capSensor3 = CapacitiveSensor(2, 3); //capSensor3-12 brukes void loop.
CapacitiveSensor capSensor4 = CapacitiveSensor(2, 4);
CapacitiveSensor capSensor5 = CapacitiveSensor(2, 5);
CapacitiveSensor capSensor6 = CapacitiveSensor(2, 6);
CapacitiveSensor capSensor7 = CapacitiveSensor(2, 7);
CapacitiveSensor capSensor8 = CapacitiveSensor(2, 8);
CapacitiveSensor capSensor9 = CapacitiveSensor(2, 9);
CapacitiveSensor capSensor10 = CapacitiveSensor(2, 10); //line20
CapacitiveSensor capSensor11 = CapacitiveSensor(2, 11);
CapacitiveSensor capSensor12 = CapacitiveSensor(2, 12);
void setup() {
for (int x = 0; x < 10;) {
array[x] = capSensor(x + 3);
}
pinMode(latchPin, OUTPUT); //Output for shift register
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Serial.begin(9600);
} //linje30
void loop() {
for (int x = 3; x < 13;) { //Checks proximity to "capSensor3-12".
T = x - 3;
array[T] = capSensor(x); //Corrected
long sensorValue = array[T].capacitiveSensor(2000); //LINE36- ERROR
Serial.print ("SensorValue=");
Serial.print (sensorValue);
Serial.print (" TAK=");
Serial.println(TAK[T]);
delay(100);
//linje40
if ( sensorValue > threshold ) { //Lights LED if "SensorValue3-10" > threshold value.
Serial.println("STORRE");
digitalWrite(latchPin, LOW); //LatchPin low so LEDs don't change while you're sending in bits.
shiftOut(dataPin, clockPin, MSBFIRST, TAK[T]); // Shift out the bits.
digitalWrite(latchPin, HIGH); //Latch pin high so the LEDs will light up.
delay(500);
}
else {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 0); // shift out the bits:
digitalWrite(latchPin, HIGH); //Do I need this to keep LEDS off ?
delay(10);
}
}
if ( sensorValue[11] > threshold )
{
digitalWrite(14, HIGH);
}
else {
digitalWrite(14, LOW);
}
if ( sensorValue[12] > threshold )
{
digitalWrite(15, HIGH);
}
else {
digitalWrite(15, LOW);
}
}