IR Rotary encoder - Debug


so have built rotary encorder using ir sender receiver. problem need print 1 once every time black mark goes past, prints multiple 1's every time mark passes though shouldn't. appreciated :) thanks

code: [select]

int powerpinsender= 7;
int powerpinreceiver = 6;

int sensorpin = a0;

int stopstartbutton = 9;
int senddatabutton = 8;

int sensorvalue = 0;
int value = 1;
int lastvalue = high;
int write = 0;

int ledstate = 1;
int pulse = 0;

void setup()
{
  serial.begin(9600);
 
  pinmode(powerpinsender, output);
  pinmode(powerpinreceiver, output);
 
  pinmode(stopstartbutton, input);
  pinmode(senddatabutton, input);
  pinmode(sensorpin, input);

  digitalwrite(powerpinsender,high);
  digitalwrite(powerpinreceiver, high);

}

void loop()
{
  sensorvalue = analogread(sensorpin);
 
  if (sensorvalue <= 10 && value == 1){
    value = 0;
  }
  if (sensorvalue > 10 && value == 1){
    value = 0;
    lastvalue = high;
  }
  if (sensorvalue <= 10 && value == 0){
    value = 1;
  }
  if (sensorvalue > 10 && value == 0 ){
    value = 0;
    lastvalue = high;
  }
   
     
  serial.println(value);
  delay(500);
}


what there in code should stop multiple printing ?

you should print value when has changed 0 1 since last time printed.  have lastvalue variable in code don't use anywhere.


Arduino Forum > Using Arduino > Programming Questions > IR Rotary encoder - Debug


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62