hi!
i´m working on a quad-encoder: Quadratrak -- Read a Quadrature Encoder -- Chuck's Robotics Notebook
something like this. as test surrounding i took 2 buttons and press them by hand.
i´ve encountered a problem with string comparison or with bit-wise comparison
int ledPin = 13;
int photopin1 = 7;
int photopin2 = 8;
int value1 = 0;
int value2 = 0;
int value = 0;
char stateprevious = '00';
char statenow = '00';
int rs232val = 0;
int delaystate = HIGH;
void setup() {
pinMode(photopin1, INPUT);
pinMode(photopin2, INPUT);
pinMode(ledPin, OUTPUT);
beginSerial(19200);
}
void check_state() {
delaystate = !delaystate;
if (value1 == HIGH && value2 == HIGH) {
if (delaystate == HIGH) {
stateprevious = '11'; }
else {
statenow = '11';
}
}
else if (value1 == LOW && value2 == HIGH) {
if (delaystate == HIGH) {
stateprevious = '01'; }
else {
statenow = '01';
}
}
else if (value1 == HIGH && value2 == LOW) {
if (delaystate == HIGH) {
stateprevious = '10'; }
else {
statenow = '10';
}
}
else if (value1 == LOW && value2 == LOW) {
if (delaystate == HIGH) {
stateprevious = '00'; }
else {
statenow = '00';
}
}
}
void loop() {
value1 = digitalRead(photopin1);
value2 = digitalRead(photopin2);
check_state();
serialWrite(statenow);
serialWrite(10);
serialWrite(13);
serialWrite(stateprevious);
serialWrite(10);
serialWrite(13);
}
in serial monitor i cant see the correct state. it only prints one character per line?!?!!