invalid conversion from "int*" to "int" - array question


guys,

i have function has 2 bytes , array input parameters , should return array.
but keep getting above mentioned error.

below program. this:
it reads rotary encoders via shiftin function. encoders connected 74hc156 multuplexer.
than mypotcalcfunction : calculates if rotary encoder has moved, calculates if went cw or ccw, calculate real value of encoder (old value + 1 cw , -1 ccw).
the pot values displayed on 16x2lcd.
i hope coments ;-)
the error in mypotcalcfunction
when put function void (loop) kind of works ;-) (it detects rotation of pots ok, +3 instead of +1???)

ps beginning of ui interfacte template; reading rotary encoders , push buttons, displaying values on lcd. next step these rotary encoders , push buttons ;-)

any appreciated.

code: [select]

//define pins shiftin
int latchpin = 8;
int datapin = 11;
int clockpin = 12;

//define variables hold data
//for each shift register.
byte switchvar1;
byte oldswitchvar1;

//define varaibles hold data
//for direction of rotary encoder (+1 or -1)
int encoders1[4];
int oldencoders1[4];

//define varaibles hold data
//for values of rotary encoders
int valuespot1[4];
int oldvaluespot1[4];

// include library code
#include <liquidcrystal.h>

// initialize library numbers of interface pins
liquidcrystal lcd(7, 6, 5, 4, 3, 2);

////------------------------------------------------start setup
void setup() {
  // set lcd's number of columns , rows:
  lcd.begin(16, 2);
  // print message lcd.
  lcd.print("hello,");
  //define pin modes
  delay(1000);
  lcd.clear();
  pinmode(latchpin, output);
  pinmode(clockpin, output);
  pinmode(datapin, input);
}
//------------------------------------------------end setup

////------------------------------------------------start main loop
void loop() {
  //but inputs of 74hc156 in buffer
  digitalwrite(latchpin, low);
  delaymicroseconds(5);
  digitalwrite(latchpin, high);
  //read inputs 74hc156
  switchvar1 = shiftin(datapin, clockpin);
  //calculate cw or ccw movement of rotary encoders
  //and calculate pot values 
  valuespot1 = mypotcalcfunction(switchvar1, oldswitchvar1, oldvaluespot1); 

  //display values of rotary encoders on lcd
  lcd.clear();
  lcd.setcursor(0, 0);
  lcd.print(values1[0]);
  lcd.setcursor(4, 0);
  lcd.print(values1[1]);
  lcd.setcursor(8, 0);
  lcd.print(values1[2]);
  lcd.setcursor(12, 0);
  lcd.print(values1[3]);
 
}}
//------------------------------------------------end main loop

////// ----------------------------------------start shiftin function 74ls156

byte shiftin(int mydatapin, int myclockpin) {
  int i;
  int temp = 0;
  int pinstate;
  byte mydatain = 0;

  pinmode(myclockpin, output);
  pinmode(mydatapin, input);
  //read byte
  (i=7; i>=0; i--)
  {
    digitalwrite(myclockpin, 0);
    //set clk pin low , read input
    delaymicroseconds(2);
    temp = digitalread(mydatapin);
    if (temp) {
      pinstate = 1;
      mydatain = mydatain | (1 << i);
      //if pin high write 1 else 0
    }
    //set clk pin low start reading next bit
    digitalwrite(myclockpin, 1);
  }
  return mydatain;
}
//------------------------------------------------end shiftin function



//-------------------------------------------------------------------------start pot calculation function

int* mypotcalcfunction(byte switchvar1, byte oldswitchvar1, int oldvaluespot1)
{
  if ((switchvar1 == 255)) //do nothing when swichvar = 11111111
    {
    }
    else
    {
    (int k = 0; k < 4; k++)    //when "k=0"
    {
      int j = (2*k)+1;        //"j=1"
      int = j-1;              // "i=0"
      int = bitread(switchvar1, i);  // = bit 0
      int b = bitread(switchvar1, j);   // b= bit 1
      int olda = bitread(oldswitchvar1, i); // read old bit
      int oldb = bitread(oldswitchvar1, j);  //read old b bit
      int c = oldvaluespot1[k];   //read old pot value
       if ((a == 1) && (b == 1))  //if , b =0 nothing
      {
      }         // next math decide if pot cw or ccw
      if ((a == 0) && (b == 0) && (olda == 0) && (oldb == 1))
      {
       encoders1[k]=-1;
       bitwrite(oldswitchvar1, i, a); //write new bit
       bitwrite(oldswitchvar1, j, b); //old bit
       valuespot1[k] = c - 1;  //calculate new pot value
       }
      if ((a == 1) && (b == 0) && (olda == 0) && (oldb == 0))
      {
       encoders1[k]=-1;
       bitwrite(oldswitchvar1, i, a);
       bitwrite(oldswitchvar1, j, b);
       valuespot1[k] = c - 1;
      }
      if ((a == 0) && (b == 1) && (olda == 1) && (oldb == 0))
      {
       encoders1[k]=-1;
       bitwrite(oldswitchvar1, i, a);
       bitwrite(oldswitchvar1, j, b);
       valuespot1[k] = c - 1;
      }
      if ((a == 0) && (b == 0) && (olda == 1) && (oldb == 0))
      {
       encoders1[k]=1;
       bitwrite(oldswitchvar1, i, a);
       bitwrite(oldswitchvar1, j, b);
       valuespot1[k] = c + 1;
      }
      if ((a == 0) && (b == 1) && (olda == 0) && (oldb == 0))
      {
       encoders1[k]=1;
       bitwrite(oldswitchvar1, i, a);
       bitwrite(oldswitchvar1, j, b);
       valuespot1[k] = c + 1;
      }
      if ((a == 1) && (b == 0) && (olda == 0) && (oldb == 1))
      {
       encoders1[k]=1;
       bitwrite(oldswitchvar1, i, a);
       bitwrite(oldswitchvar1, j, b);
       valuespot1[k] = c + 1;
      }
     else
      {
        //if value changed , not 11, before??
        encoders1[k]=oldencoders1[k]; //what pot values calculation?
      }
      oldvaluespot1[k] = valuespot1[k]; //make new old
      oldencoders1[k] = encoders1[k];  //make new old
     }
  return valuespot1; //for further use
  return oldvaluespot1; //for reuse in loop
}   
//----------------------------------------------end pot calculation function

also, 2 consecutive returns programmer expects.


Arduino Forum > Using Arduino > Programming Questions > invalid conversion from "int*" to "int" - array question


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial