Gist with switch() problem and error message
Trying to code a rotary encoder sketch to make use of a switch statement.
switch(encoder_positions) produces compiler error: Compilation error: switch quantity not an integer I am assigning an ASCII, decimal code to each detent on the 36 detent, incremental rotary encoder.
Have been unable to find correct variable to use with the switch statement. Need to pass the current position value to the switch statement.
William
hello,
why so complicated ?
numero : select the rotate switch
designed by “enc”
function below to get back the ascii for one rotate swich
“result” must be declared as global ..
void rotSwitch(char numero) //Rotary encoder conversion to ASCII { if (encoder_positions[numero]< 27) result= 65 + encoder_positions[numero]; else result= 48 + encoder_positions[numero]-27; }
Hello paulfjujo,
First experience working with rotary encoders.
I follow the method of converting letters and numbers; how does numero come into play? How do I select rotary encoder. Will be using four rotary encoders in project; result going to a quad alphanumeric display.
Have been unable display result to quad, alphanumeric display.
Regards,
William
hello,
how does numero come into play?
numéro is only a parameter … it could be used to pass “enc” as parameter
void loop()
{
for (uint8_t enc=0; enc<sizeof(found_encoders); enc++)
{
if (found_encoders[enc] == false) continue;
int32_t new_position = encoders[enc].getEncoderPosition();
// did we move around?
if (encoder_positions[enc] != new_position) {
Serial.print("Encoder #");
Serial.print(enc);
Serial.print(" -> ");
//---------------------------------------
if (encoder_positions[enc]< 27)
result= 65 + encoder_positions[enc];
else
result= 48 + encoder_positions[enc]-27;
Serial.write(result); //ASCII Char code in decimal
encoder_positions[enc] = new_position;
// -------------------------------
// change the neopixel color, mulitply the new positiion by 4 to speed it up
encoder_pixels[enc].setPixelColor(0, Wheel((new_position*4) & 0xFF));
encoder_pixels[enc].show();
} if (! encoders[enc].digitalRead(SS_SWITCH)) {
Serial.print("Encoder #");
Serial.print(enc);
Serial.println(" pressed");
}
}
}
I have a value that is the decimal equivalent of an ASCII, upper case character.
Having been unable to display using:
char letter = char(result);
display.printChar(letter, 0);
//———————————————
Have also tried: display.printChar(char(result), 0);
Code compiles; encoder_position[enc] value is captured, as well as new_position. result is getting a value. Still no display on digit 0 of display. Serial.println(result); produces 84, Serial.write(result); produces T.
William
hello,
Serial.println(result); //produces ascii value=84,
Serial.write(result);// produces ascii ‘T’. ..OK, Normal !
try with :
you can also use :
char letter =(char)result; // Cast int value (16bits) into a char value (8 bits)
display.printChar((char)result, 0); // i suppose result is numerique ‘0’ to ‘9’
display.printChar(‘O’, 1); // is it ‘O’ letter or zero value ‘0’ ?
display.printChar(‘O’, 2);
display.printChar(‘O’, 3);