Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, I am doing a project of arduino to control the relay switch by using the CapacitiveSensor

i found that there is some error on my array.

not sure is there any problem in my setup for array

please advice thank you,

I am still new in c++ programming

What I have tried:

C++
<pre>#include <CapacitiveSensor.h>

CapacitiveSensor _pianoTiles[] = {};

/*
   * pin2 Piezo's Ports
   * pin3 ~ pin6 Relay Switch's Ports
   */
   
  int _outputPorts[] = {2 , 3 , 4 , 5 , 6}; 

  /*
   * pin10 ~ 13 : capacitiveSensor's Ports
   */

   int _inputPorts[] = {10, 11, 12, 13};

void setup() {

  //boundRate:
  Serial.begin  (9600);

  for ( int inputPorts = 0 ; inputPorts < sizeof( _inputPorts ) - 1 ; inputPorts ++) _pianoTiles[inputPorts] = CapacitiveSensor( 9 , _inputPorts[inputPorts]);

  for ( int outputPorts = 0 ; outputPorts < sizeof( _outputPorts ) - 1 ; outputPorts ++ ) pinMode ( _outputPorts[outputPorts], OUTPUT);

}

void loop() {

  int value[]={};

  for ( int i = 0 ; i < sizeof( _pianoTiles ) - 1 ; i ++ ) value[i] = _pianoTiles[i].capacitiveSensor(30);

  if ( _pianoTiles[0] > 200 ) digitalWrite( 2 , 1 );

}



there is an error on this line :
<pre>if ( _pianoTiles[0] > 200 ) digitalWrite( 2 , 1 );


error message :
Arduino: 1.8.3 Hourly Build 2017/04/14 10:33 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\racheal\Desktop\smchProject\smchProject.ino: In function 'void loop()':

smchProject:35: error: no match for 'operator>' (operand types are 'CapacitiveSensor' and 'int')

   if ( _pianoTiles[0] > 200 ) digitalWrite( 2 , 1 );

                       ^

exit status 1
no match for 'operator>' (operand types are 'CapacitiveSensor' and 'int')

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Posted
Updated 16-Apr-17 22:09pm

1 solution

The error message is pretty explicit:
no match for 'operator>' (operand types are 'CapacitiveSensor' and 'int')

So look at the code:
if ( _pianoTiles[0] > 200 ) ...

_pianoTilesis declared as an array of CapacitiveSensor objects:
C++
CapacitiveSensor _pianoTiles[] = {};
And 200 is obviously an integer.
The error message is telling you that there is not operator declared which allows the system to tell which of the two object types CapacitiveSensor and integer is the "biggest".

Either define a operator> for CapacitiveSensor that takes an integer, or sort out which part of the CapacitiveSensor you meant to compare.
 
Share this answer
 
Comments
KarstenK 21-Apr-17 11:17am    
I think fixing that compiler error isnt the last step, but the complete handling of the array need a redesign. It startes with the initialization the array...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900